diff --git a/molecule/default_vagrant/converge.yml b/molecule/default_vagrant/converge.yml new file mode 100644 index 0000000..6c10078 --- /dev/null +++ b/molecule/default_vagrant/converge.yml @@ -0,0 +1,7 @@ +--- +- name: Converge + hosts: all + tasks: + - name: "Include ednxzu.manage_pipx_packages" + ansible.builtin.include_role: + name: "ednxzu.manage_pipx_packages" diff --git a/molecule/default_vagrant/molecule.yml b/molecule/default_vagrant/molecule.yml new file mode 100644 index 0000000..2b02360 --- /dev/null +++ b/molecule/default_vagrant/molecule.yml @@ -0,0 +1,35 @@ +--- +dependency: + name: galaxy + options: + requirements-file: ./requirements.yml +driver: + name: vagrant + provider: + name: libvirt +platforms: + - name: instance + box: generic/${MOLECULE_TEST_OS} + cpus: 4 + memory: 4096 +provisioner: + name: ansible + config_options: + defaults: + remote_tmp: /tmp/.ansible +verifier: + name: ansible +scenario: + name: default_vagrant + test_sequence: + - dependency + - cleanup + - destroy + - syntax + - create + - prepare + - converge + - idempotence + - verify + - cleanup + - destroy diff --git a/molecule/default_vagrant/requirements.yml b/molecule/default_vagrant/requirements.yml new file mode 100644 index 0000000..ca250b7 --- /dev/null +++ b/molecule/default_vagrant/requirements.yml @@ -0,0 +1,4 @@ +--- +# requirements file for molecule +roles: + - name: ednxzu.manage_apt_packages diff --git a/molecule/default_vagrant/verify.yml b/molecule/default_vagrant/verify.yml new file mode 100644 index 0000000..55620b7 --- /dev/null +++ b/molecule/default_vagrant/verify.yml @@ -0,0 +1,47 @@ +--- +- name: Verify + hosts: all + gather_facts: true + tasks: + - name: "Test: file /etc/hosts" + block: + - name: "Stat file /etc/hosts" + ansible.builtin.stat: + path: "/etc/hosts" + register: stat_etc_hosts + + - name: "Verify file /etc/hosts" + vars: + etc_hosts_group: + ubuntu: "adm" + debian: "root" + ansible.builtin.assert: + that: + - stat_etc_hosts.stat.exists + - stat_etc_hosts.stat.isreg + - stat_etc_hosts.stat.pw_name == 'root' + - stat_etc_hosts.stat.gr_name == etc_hosts_group[(ansible_distribution|lower)] + + - name: "Test: packages ansible-lint" + block: + - name: "Get pipx installed packages" + ansible.builtin.command: "pipx list --json" + environment: + PIPX_HOME: "/opt/pipx" + changed_when: false + register: pipx_installed_packages + become: true + + - name: "Set fact" + ansible.builtin.set_fact: + pipx_simple_list: "{{ pipx_simple_list | default({}) | combine({item.key: item.value.metadata.main_package.package_version}) }}" + loop: "{{ pipx_installed_packages.stdout | from_json | json_query('venvs') | dict2items }}" + + - name: "Verify packages ansible-lint" + ansible.builtin.assert: + that: + - pipx_simple_list['ansible-lint'] is defined + + - name: "Print installed packages" + ansible.builtin.debug: + msg: "{{ pipx_simple_list }}" diff --git a/molecule/with_custom_packages_vagrant/converge.yml b/molecule/with_custom_packages_vagrant/converge.yml new file mode 100644 index 0000000..6c10078 --- /dev/null +++ b/molecule/with_custom_packages_vagrant/converge.yml @@ -0,0 +1,7 @@ +--- +- name: Converge + hosts: all + tasks: + - name: "Include ednxzu.manage_pipx_packages" + ansible.builtin.include_role: + name: "ednxzu.manage_pipx_packages" diff --git a/molecule/with_custom_packages_vagrant/group_vars/all.yml b/molecule/with_custom_packages_vagrant/group_vars/all.yml new file mode 100644 index 0000000..8b262da --- /dev/null +++ b/molecule/with_custom_packages_vagrant/group_vars/all.yml @@ -0,0 +1,14 @@ +--- +manage_pipx_packages_install_prereqs: true +manage_pipx_packages_home: "/opt/pipx" +manage_pipx_packages_path: "/usr/local/bin" +manage_pipx_packages_list: + - name: ansible-core + version_constraint: latest + state: present + - name: yamllint + version_constraint: latest + state: present + - name: vault-cli + version_constraint: latest + state: present diff --git a/molecule/with_custom_packages_vagrant/molecule.yml b/molecule/with_custom_packages_vagrant/molecule.yml new file mode 100644 index 0000000..c5529df --- /dev/null +++ b/molecule/with_custom_packages_vagrant/molecule.yml @@ -0,0 +1,35 @@ +--- +dependency: + name: galaxy + options: + requirements-file: ./requirements.yml +driver: + name: vagrant + provider: + name: libvirt +platforms: + - name: instance + box: generic/${MOLECULE_TEST_OS} + cpus: 4 + memory: 4096 +provisioner: + name: ansible + config_options: + defaults: + remote_tmp: /tmp/.ansible +verifier: + name: ansible +scenario: + name: with_custom_packages_vagrant + test_sequence: + - dependency + - cleanup + - destroy + - syntax + - create + - prepare + - converge + - idempotence + - verify + - cleanup + - destroy diff --git a/molecule/with_custom_packages_vagrant/requirements.yml b/molecule/with_custom_packages_vagrant/requirements.yml new file mode 100644 index 0000000..ca250b7 --- /dev/null +++ b/molecule/with_custom_packages_vagrant/requirements.yml @@ -0,0 +1,4 @@ +--- +# requirements file for molecule +roles: + - name: ednxzu.manage_apt_packages diff --git a/molecule/with_custom_packages_vagrant/verify.yml b/molecule/with_custom_packages_vagrant/verify.yml new file mode 100644 index 0000000..8282a03 --- /dev/null +++ b/molecule/with_custom_packages_vagrant/verify.yml @@ -0,0 +1,49 @@ +--- +- name: Verify + hosts: all + gather_facts: true + tasks: + - name: "Test: file /etc/hosts" + block: + - name: "Stat file /etc/hosts" + ansible.builtin.stat: + path: "/etc/hosts" + register: stat_etc_hosts + + - name: "Verify file /etc/hosts" + vars: + etc_hosts_group: + ubuntu: "adm" + debian: "root" + ansible.builtin.assert: + that: + - stat_etc_hosts.stat.exists + - stat_etc_hosts.stat.isreg + - stat_etc_hosts.stat.pw_name == 'root' + - stat_etc_hosts.stat.gr_name == etc_hosts_group[(ansible_distribution|lower)] + + - name: "Test: packages pip, vault-cli, yamllint, ansible-core" + block: + - name: "Get pipx installed packages" + ansible.builtin.command: "pipx list --json" + environment: + PIPX_HOME: "/opt/pipx" + changed_when: false + register: pipx_installed_packages + become: true + + - name: "Set fact" + ansible.builtin.set_fact: + pipx_simple_list: "{{ pipx_simple_list | default({}) | combine({item.key: item.value.metadata.main_package.package_version}) }}" + loop: "{{ pipx_installed_packages.stdout | from_json | json_query('venvs') | dict2items }}" + + - name: "Verify packages pip, vault-cli, yamllint, ansible-core" + ansible.builtin.assert: + that: + - pipx_simple_list['yamllint'] is defined + - pipx_simple_list['ansible-core'] is defined + - pipx_simple_list['vault-cli'] is defined + + - name: "Print installed packages" + ansible.builtin.debug: + msg: "{{ pipx_simple_list }}" diff --git a/tasks/main.yml b/tasks/main.yml index 6f36c4b..a6d8316 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -14,3 +14,4 @@ loop: "{{ manage_pipx_packages_list }}" when: manage_pipx_packages_list is defined and manage_pipx_packages_list not in [None, ''] + become: true