added custom test, but pipx module isnt idempotent
This commit is contained in:
parent
1dd86348a9
commit
84c0b6d243
@ -1,7 +1,8 @@
|
|||||||
---
|
---
|
||||||
# defaults file for manage_pipx_packages
|
# defaults file for manage_pipx_packages
|
||||||
manage_pipx_packages_install_prereqs: true
|
manage_pipx_packages_install_prereqs: true
|
||||||
|
manage_pipx_packages_path: "/usr/local/bin"
|
||||||
manage_pipx_packages_list:
|
manage_pipx_packages_list:
|
||||||
- name: pip
|
- name: ansible-core
|
||||||
version_constraint: latest
|
version_constraint: latest
|
||||||
state: present
|
state: present
|
||||||
|
4
molecule/default/requirements.yml
Normal file
4
molecule/default/requirements.yml
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
---
|
||||||
|
# requirements file for molecule
|
||||||
|
roles:
|
||||||
|
- name: ednxzu.manage_apt_packages
|
7
molecule/with_custom_packages/converge.yml
Normal file
7
molecule/with_custom_packages/converge.yml
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
---
|
||||||
|
- name: Converge
|
||||||
|
hosts: all
|
||||||
|
tasks:
|
||||||
|
- name: "Include ednxzu.manage_pipx_packages"
|
||||||
|
ansible.builtin.include_role:
|
||||||
|
name: "ednxzu.manage_pipx_packages"
|
13
molecule/with_custom_packages/group_vars/all.yml
Normal file
13
molecule/with_custom_packages/group_vars/all.yml
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
---
|
||||||
|
manage_pipx_packages_install_prereqs: true
|
||||||
|
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
|
37
molecule/with_custom_packages/molecule.yml
Normal file
37
molecule/with_custom_packages/molecule.yml
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
---
|
||||||
|
dependency:
|
||||||
|
name: galaxy
|
||||||
|
options:
|
||||||
|
requirements-file: ./requirements.yml
|
||||||
|
driver:
|
||||||
|
name: docker
|
||||||
|
platforms:
|
||||||
|
- name: instance
|
||||||
|
image: geerlingguy/docker-${MOLECULE_TEST_OS}-ansible
|
||||||
|
command: ""
|
||||||
|
volumes:
|
||||||
|
- /sys/fs/cgroup:/sys/fs/cgroup
|
||||||
|
cgroupns_mode: host
|
||||||
|
privileged: true
|
||||||
|
pre_build_image: true
|
||||||
|
provisioner:
|
||||||
|
name: ansible
|
||||||
|
config_options:
|
||||||
|
defaults:
|
||||||
|
remote_tmp: /tmp/.ansible
|
||||||
|
verifier:
|
||||||
|
name: ansible
|
||||||
|
scenario:
|
||||||
|
name: with_custom_packages
|
||||||
|
test_sequence:
|
||||||
|
- dependency
|
||||||
|
- cleanup
|
||||||
|
- destroy
|
||||||
|
- syntax
|
||||||
|
- create
|
||||||
|
- prepare
|
||||||
|
- converge
|
||||||
|
- idempotence
|
||||||
|
- verify
|
||||||
|
- cleanup
|
||||||
|
- destroy
|
4
molecule/with_custom_packages/requirements.yml
Normal file
4
molecule/with_custom_packages/requirements.yml
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
---
|
||||||
|
# requirements file for molecule
|
||||||
|
roles:
|
||||||
|
- name: ednxzu.manage_apt_packages
|
46
molecule/with_custom_packages/verify.yml
Normal file
46
molecule/with_custom_packages/verify.yml
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
---
|
||||||
|
- name: Verify
|
||||||
|
hosts: all
|
||||||
|
gather_facts: false
|
||||||
|
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"
|
||||||
|
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 == 'root'
|
||||||
|
|
||||||
|
- name: "Test: packages pip, vault-cli, yamllint, docker"
|
||||||
|
block:
|
||||||
|
- name: "Get pip3 up-to-date packages"
|
||||||
|
ansible.builtin.command: "pip3 list -u --format=json"
|
||||||
|
changed_when: false
|
||||||
|
register: pip_updated_packages
|
||||||
|
|
||||||
|
- name: "Get pip3 out-of-date packages"
|
||||||
|
ansible.builtin.command: "pip3 list -o --format=json"
|
||||||
|
changed_when: false
|
||||||
|
register: pip_outdated_packages
|
||||||
|
|
||||||
|
- 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') }}"
|
||||||
|
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"
|
@ -2,12 +2,14 @@
|
|||||||
# task/main file for manage_pipx_packages
|
# task/main file for manage_pipx_packages
|
||||||
- name: "Import prerequisites.yml"
|
- name: "Import prerequisites.yml"
|
||||||
ansible.builtin.include_tasks: prerequisites.yml
|
ansible.builtin.include_tasks: prerequisites.yml
|
||||||
when: manage_pip_packages_install_prereqs
|
when: manage_pipx_packages_install_prereqs
|
||||||
|
|
||||||
- name: "Install/remove required pip packages"
|
- name: "Install/remove required pip packages"
|
||||||
community.general.pipx:
|
community.general.pipx:
|
||||||
name: "{{ item.name }}{% if item.version_constraint not in [None, '', 'latest'] %}{{ item.version_constraint }}{% endif %}"
|
name: "{{ item.name }}{% if item.version_constraint not in [None, '', 'latest'] %}{{ item.version_constraint }}{% endif %}"
|
||||||
state: "{{ item.state }}"
|
state: "{{ item.state }}"
|
||||||
loop: "{{ manage_pip_packages_list }}"
|
# environment:
|
||||||
when: manage_pip_packages_list is defined
|
# PIPX_BIN_DIR: "{{ manage_pipx_packages_path }}"
|
||||||
and manage_pip_packages_list not in [None, '']
|
loop: "{{ manage_pipx_packages_list }}"
|
||||||
|
when: manage_pipx_packages_list is defined
|
||||||
|
and manage_pipx_packages_list not in [None, '']
|
||||||
|
Loading…
Reference in New Issue
Block a user