start of ansible tests cause molecule is deprecating testinfra

This commit is contained in:
Bertrand Lanson 2023-07-16 22:04:43 +02:00
parent 33b1f444b7
commit 6b2da1707a
3 changed files with 64 additions and 44 deletions

View File

@ -20,7 +20,7 @@ provisioner:
defaults: defaults:
remote_tmp: /tmp/.ansible remote_tmp: /tmp/.ansible
verifier: verifier:
name: testinfra name: ansible
scenario: scenario:
name: default name: default
test_sequence: test_sequence:

View File

@ -18,50 +18,50 @@
- stat_etc_hosts.stat.pw_name == 'root' - stat_etc_hosts.stat.pw_name == 'root'
- stat_etc_hosts.stat.gr_name == 'root' - stat_etc_hosts.stat.gr_name == 'root'
- name: "Test: ansible user and group" - name: "Test: ubuntu user and group"
block: block:
- name: "Getent user ansible" - name: "Getent user ansible"
ansible.builtin.getent: ansible.builtin.getent:
database: passwd database: passwd
key: deploy key: ubuntu
register: ansible_user register: ednxzu_management_user
- name: "Getent group ansible" - name: "Getent group ubuntu"
ansible.builtin.getent: ansible.builtin.getent:
database: group database: group
key: deploy key: ubuntu
register: ansible_group register: ednxzu_management_group
- name: "Verify ansible user and group" - name: "Verify ubuntu user and group"
ansible.builtin.assert: ansible.builtin.assert:
that: that:
- not ansible_user.failed - not ednxzu_management_user.failed
- not ansible_group.failed - not ednxzu_management_group.failed
- "'deploy' in ansible_user.ansible_facts.getent_passwd.keys()" - "'ubuntu' in ednxzu_management_user.ansible_facts.getent_passwd.keys()"
- "'/opt/deploy' in ansible_user.ansible_facts.getent_passwd['deploy']" - "'/home/ubuntu' in ednxzu_management_user.ansible_facts.getent_passwd['ubuntu']"
- "'/bin/bash' in ansible_user.ansible_facts.getent_passwd['deploy']" - "'/bin/bash' in ednxzu_management_user.ansible_facts.getent_passwd['ubuntu']"
- "'deploy' in ansible_group.ansible_facts.getent_group.keys()" - "'ubuntu' in ednxzu_management_group.ansible_facts.getent_group.keys()"
- name: "Test: ansible sudo permissions" - name: "Test: ubuntu sudo permissions"
block: block:
- name: "Stat file /etc/sudoers.d/deploy" - name: "Stat file /etc/sudoers.d/ubuntu"
ansible.builtin.stat: ansible.builtin.stat:
path: "/etc/sudoers.d" path: "/etc/sudoers.d/ubuntu"
register: stat_etc_sudoers_d_ansible register: stat_etc_sudoers_d_ubuntu
- name: "Verify file /etc/sudoers.d/deploy" - name: "Verify file /etc/sudoers.d/ubuntu"
ansible.builtin.assert: ansible.builtin.assert:
that: that:
- not stat_etc_sudoers_d_ansible.stat.exists - not stat_etc_sudoers_d_ubuntu.stat.exists
- name: "Test: ansible authorized_keys" - name: "Test: ubuntu authorized_keys"
block: block:
- name: "Stat file /opt/deploy/.ssh/authorized_keys" - name: "Stat file /home/ubuntu/.ssh/authorized_keys"
ansible.builtin.stat: ansible.builtin.stat:
path: "/opt/deploy/.ssh/authorized_keys" path: "/home/ubuntu/.ssh/authorized_keys"
register: stat_opt_ansible_ssh_authorized_keys register: stat_home_ubuntu_ssh_authorized_keys
- name: "Verify file /opt/deploy/.ssh/authorized_keys" - name: "Verify file /home/ubuntu/.ssh/authorized_keys"
ansible.builtin.assert: ansible.builtin.assert:
that: that:
- not stat_opt_ansible_ssh_authorized_keys.stat.exists - not stat_home_ubuntu_ssh_authorized_keys.stat.exists

View File

@ -23,45 +23,65 @@
- name: "Getent user ansible" - name: "Getent user ansible"
ansible.builtin.getent: ansible.builtin.getent:
database: passwd database: passwd
key: deploy key: ansible
register: ansible_user register: ednxzu_ansible_user
- name: "Getent group ansible" - name: "Getent group ansible"
ansible.builtin.getent: ansible.builtin.getent:
database: group database: group
key: deploy key: ansible
register: ansible_group register: ednxzu_ansible_group
- name: "Verify ansible user and group" - name: "Verify ansible user and group"
ansible.builtin.assert: ansible.builtin.assert:
that: that:
- not ansible_user.failed - not ednxzu_ansible_user.failed
- not ansible_group.failed - not ednxzu_ansible_group.failed
- "'deploy' in ansible_user.ansible_facts.getent_passwd.keys()" - "'ansible' in ednxzu_ansible_user.ansible_facts.getent_passwd.keys()"
- "'/opt/deploy' in ansible_user.ansible_facts.getent_passwd['deploy']" - "'/opt/ansible' in ednxzu_ansible_user.ansible_facts.getent_passwd['ansible']"
- "'/bin/bash' in ansible_user.ansible_facts.getent_passwd['deploy']" - "'/bin/bash' in ednxzu_ansible_user.ansible_facts.getent_passwd['ansible']"
- "'deploy' in ansible_group.ansible_facts.getent_group.keys()" - "'ansible' in ednxzu_ansible_group.ansible_facts.getent_group.keys()"
- name: "Test: ansible sudo permissions" - name: "Test: ansible sudo permissions"
block: block:
- name: "Stat file /etc/sudoers.d/deploy" - name: "Stat file /etc/sudoers.d/ansible"
ansible.builtin.stat: ansible.builtin.stat:
path: "/etc/sudoers.d" path: "/etc/sudoers.d/ansible"
register: stat_etc_sudoers_d_ansible register: stat_etc_sudoers_d_ansible
- name: "Verify file /etc/sudoers.d/deploy" - name: "Slurp file /etc/sudoers.d/ansible"
ansible.builtin.slurp:
src: "/etc/sudoers.d/ansible"
register: slurp_etc_sudoers_d_ansible
- name: "Verify file /etc/sudoers.d/ansible"
ansible.builtin.assert: ansible.builtin.assert:
that: that:
- not stat_etc_sudoers_d_ansible.stat.exists - stat_etc_sudoers_d_ansible.stat.exists
- stat_etc_sudoers_d_ansible.stat.isreg
- stat_etc_sudoers_d_ansible.stat.pw_name == 'root'
- stat_etc_sudoers_d_ansible.stat.gr_name == 'root'
- stat_etc_sudoers_d_ansible.stat.mode == '0440'
- "'ansible ALL=NOPASSWD:SETENV: ALL' in (slurp_etc_sudoers_d_ansible.content|b64decode)"
- name: "Test: ansible authorized_keys" - name: "Test: ansible authorized_keys"
block: block:
- name: "Stat file /opt/deploy/.ssh/authorized_keys" - name: "Stat file /opt/ansible/.ssh/authorized_keys"
ansible.builtin.stat: ansible.builtin.stat:
path: "/opt/deploy/.ssh/authorized_keys" path: "/opt/ansible/.ssh/authorized_keys"
register: stat_opt_ansible_ssh_authorized_keys register: stat_opt_ansible_ssh_authorized_keys
- name: "Verify file /opt/deploy/.ssh/authorized_keys" - name: "Slurp file /opt/ansible/.ssh/authorized_keys"
ansible.builtin.slurp:
src: "/opt/ansible/.ssh/authorized_keys"
register: slurp_opt_ansible_ssh_authorized_keys
- name: "Verify file /opt/ansible/.ssh/authorized_keys"
ansible.builtin.assert: ansible.builtin.assert:
that: that:
- not stat_opt_ansible_ssh_authorized_keys.stat.exists - stat_opt_ansible_ssh_authorized_keys.stat.exists
- stat_opt_ansible_ssh_authorized_keys.stat.isreg
- stat_opt_ansible_ssh_authorized_keys.stat.pw_name == 'ansible'
- stat_opt_ansible_ssh_authorized_keys.stat.gr_name == 'ansible'
- stat_opt_ansible_ssh_authorized_keys.stat.mode == '0600'
- "'ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIClfmTk73wNNL2jwvhRUmUuy80JRrz3P7cEgXUqlc5O9 ansible@instance' in (slurp_opt_ansible_ssh_authorized_keys.content|b64decode)"