2023-07-12 20:35:33 +00:00
|
|
|
---
|
|
|
|
- name: Verify
|
|
|
|
hosts: all
|
2023-12-03 17:08:11 +00:00
|
|
|
gather_facts: true
|
|
|
|
become: true
|
2023-07-12 20:35:33 +00:00
|
|
|
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-12 20:35:33 +00:00
|
|
|
|
2023-07-13 21:51:00 +00:00
|
|
|
- name: "Getent group ansible"
|
2023-07-12 20:35:33 +00:00
|
|
|
ansible.builtin.getent:
|
|
|
|
database: group
|
2023-07-14 22:13:04 +00:00
|
|
|
key: ansible
|
|
|
|
register: ednxzu_ansible_group
|
2023-07-12 20:35:33 +00:00
|
|
|
|
|
|
|
- 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()"
|
2023-07-12 20:35:33 +00:00
|
|
|
|
|
|
|
- name: "Test: ansible sudo permissions"
|
|
|
|
block:
|
2023-07-14 22:13:04 +00:00
|
|
|
- name: "Stat file /etc/sudoers.d/ansible"
|
2023-07-12 20:35:33 +00:00
|
|
|
ansible.builtin.stat:
|
2023-07-14 22:13:04 +00:00
|
|
|
path: "/etc/sudoers.d/ansible"
|
2023-07-12 20:35:33 +00:00
|
|
|
register: stat_etc_sudoers_d_ansible
|
|
|
|
|
2023-07-14 22:13:04 +00:00
|
|
|
- name: "Verify file /etc/sudoers.d/ansible"
|
2023-07-12 20:35:33 +00:00
|
|
|
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"
|
2023-07-12 20:35:33 +00:00
|
|
|
ansible.builtin.stat:
|
2023-07-14 22:13:04 +00:00
|
|
|
path: "/opt/ansible/.ssh/authorized_keys"
|
2023-07-12 20:35:33 +00:00
|
|
|
register: stat_opt_ansible_ssh_authorized_keys
|
|
|
|
|
2023-07-14 22:13:04 +00:00
|
|
|
- name: "Verify file /opt/ansible/.ssh/authorized_keys"
|
2023-07-12 20:35:33 +00:00
|
|
|
ansible.builtin.assert:
|
|
|
|
that:
|
|
|
|
- not stat_opt_ansible_ssh_authorized_keys.stat.exists
|