added 2nd molecule test and they work now

This commit is contained in:
Bertrand Lanson 2023-08-24 21:55:43 +02:00
parent 84c0b6d243
commit 99429ad930
3 changed files with 41 additions and 22 deletions

View File

@ -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 }}"

View File

@ -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 }}"

View File

@ -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, '']