provision_ansible_user/molecule/default/verify.yml

54 lines
1.8 KiB
YAML
Raw Normal View History

---
- name: Verify
hosts: all
2023-12-03 17:08:11 +00:00
gather_facts: true
become: true
tasks:
- name: "Test: ansible user and group"
block:
- name: "Getent user ansible"
ansible.builtin.getent:
database: passwd
2023-07-14 22:13:04 +00:00
key: ansible
register: ednxzu_ansible_user
2023-07-13 21:51:00 +00:00
- name: "Getent group ansible"
ansible.builtin.getent:
database: group
2023-07-14 22:13:04 +00:00
key: ansible
register: ednxzu_ansible_group
- name: "Verify ansible user and group"
ansible.builtin.assert:
that:
2023-07-14 22:13:04 +00:00
- not ednxzu_ansible_user.failed
- not ednxzu_ansible_group.failed
- "'ansible' in ednxzu_ansible_user.ansible_facts.getent_passwd.keys()"
- "'/opt/ansible' in ednxzu_ansible_user.ansible_facts.getent_passwd['ansible']"
- "'/bin/bash' in ednxzu_ansible_user.ansible_facts.getent_passwd['ansible']"
- "'ansible' in ednxzu_ansible_group.ansible_facts.getent_group.keys()"
- name: "Test: ansible sudo permissions"
block:
2023-07-14 22:13:04 +00:00
- name: "Stat file /etc/sudoers.d/ansible"
ansible.builtin.stat:
2023-07-14 22:13:04 +00:00
path: "/etc/sudoers.d/ansible"
register: stat_etc_sudoers_d_ansible
2023-07-14 22:13:04 +00:00
- name: "Verify file /etc/sudoers.d/ansible"
ansible.builtin.assert:
that:
- not stat_etc_sudoers_d_ansible.stat.exists
- name: "Test: ansible authorized_keys"
block:
2023-07-14 22:13:04 +00:00
- name: "Stat file /opt/ansible/.ssh/authorized_keys"
ansible.builtin.stat:
2023-07-14 22:13:04 +00:00
path: "/opt/ansible/.ssh/authorized_keys"
register: stat_opt_ansible_ssh_authorized_keys
2023-07-14 22:13:04 +00:00
- name: "Verify file /opt/ansible/.ssh/authorized_keys"
ansible.builtin.assert:
that:
- not stat_opt_ansible_ssh_authorized_keys.stat.exists