diff --git a/molecule/default/verify.yml b/molecule/default/verify.yml index bf52da2..2867fc8 100644 --- a/molecule/default/verify.yml +++ b/molecule/default/verify.yml @@ -17,3 +17,26 @@ - stat_etc_hosts.stat.isreg - stat_etc_hosts.stat.pw_name == 'root' - stat_etc_hosts.stat.gr_name == 'root' + + - name: "Test: packages ansible-core" + block: + - name: "Get pipx installed packages" + ansible.builtin.command: "pipx list --json" + changed_when: false + register: pipx_installed_packages + + - 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-core" + ansible.builtin.assert: + that: + - pipx_simple_list['yamllint'] is not defined + - pipx_simple_list['ansible-core'] is defined + - pipx_simple_list['vault-cli'] is not defined + + - name: "Print installed packages" + ansible.builtin.debug: + msg: "{{ pipx_simple_list }}" diff --git a/molecule/with_custom_packages/verify.yml b/molecule/with_custom_packages/verify.yml index d0c1d64..fd60972 100644 --- a/molecule/with_custom_packages/verify.yml +++ b/molecule/with_custom_packages/verify.yml @@ -18,29 +18,25 @@ - stat_etc_hosts.stat.pw_name == 'root' - stat_etc_hosts.stat.gr_name == 'root' - - name: "Test: packages pip, vault-cli, yamllint, docker" + - name: "Test: packages pip, vault-cli, yamllint, ansible-core" block: - - name: "Get pip3 up-to-date packages" - ansible.builtin.command: "pip3 list -u --format=json" + - name: "Get pipx installed packages" + ansible.builtin.command: "pipx list --json" changed_when: false - register: pip_updated_packages + register: pipx_installed_packages - - name: "Get pip3 out-of-date packages" - ansible.builtin.command: "pip3 list -o --format=json" - changed_when: false - register: pip_outdated_packages + - 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, docker" - vars: - pip_up_to_date_list: "{{ pip_updated_packages.stdout | from_json | json_query('[].name') }}" - pip_out_of_date_list: "{{ pip_outdated_packages.stdout | from_json | json_query('[].name') }}" + - name: "Verify packages pip, vault-cli, yamllint, ansible-core" ansible.builtin.assert: that: - - "'pip' in pip_up_to_date_list" - - "'pip' not in pip_out_of_date_list" - - "'vault-cli' not in pip_up_to_date_list" - - "'vault-cli' in pip_out_of_date_list" - - "'yamllint' not in pip_up_to_date_list" - - "'yamllint' in pip_out_of_date_list" - - "'docker' in pip_up_to_date_list" - - "'docker' not in pip_out_of_date_list" + - 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 d3bca7c..9285053 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -8,8 +8,8 @@ community.general.pipx: name: "{{ item.name }}{% if item.version_constraint not in [None, '', 'latest'] %}{{ item.version_constraint }}{% endif %}" state: "{{ item.state }}" - # environment: - # PIPX_BIN_DIR: "{{ manage_pipx_packages_path }}" + environment: + PIPX_BIN_DIR: "{{ manage_pipx_packages_path }}" loop: "{{ manage_pipx_packages_list }}" when: manage_pipx_packages_list is defined and manage_pipx_packages_list not in [None, '']