provision_management_user/molecule/default/verify.yml

68 lines
2.2 KiB
YAML
Raw Normal View History

2023-06-10 20:42:37 +00:00
---
- 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'
2023-07-13 21:50:24 +00:00
- name: "Test: ansible user and group"
2023-06-10 20:42:37 +00:00
block:
2023-07-13 21:50:24 +00:00
- name: "Getent user ansible"
2023-06-10 20:42:37 +00:00
ansible.builtin.getent:
database: passwd
2023-07-13 21:50:24 +00:00
key: deploy
register: ansible_user
2023-06-10 20:42:37 +00:00
2023-07-13 21:50:24 +00:00
- name: "Getent group ansible"
2023-06-10 20:42:37 +00:00
ansible.builtin.getent:
database: group
2023-07-13 21:50:24 +00:00
key: deploy
register: ansible_group
2023-06-10 20:42:37 +00:00
2023-07-13 21:50:24 +00:00
- name: "Verify ansible user and group"
2023-06-10 20:42:37 +00:00
ansible.builtin.assert:
that:
2023-07-13 21:50:24 +00:00
- not ansible_user.failed
- not ansible_group.failed
- "'deploy' in ansible_user.ansible_facts.getent_passwd.keys()"
- "'/opt/deploy' in ansible_user.ansible_facts.getent_passwd['deploy']"
- "'/bin/bash' in ansible_user.ansible_facts.getent_passwd['deploy']"
- "'deploy' in ansible_group.ansible_facts.getent_group.keys()"
- name: "Test: ansible sudo permissions"
2023-06-10 20:42:37 +00:00
block:
2023-07-13 21:50:24 +00:00
- name: "Stat file /etc/sudoers.d/deploy"
2023-06-10 20:42:37 +00:00
ansible.builtin.stat:
2023-07-13 21:50:24 +00:00
path: "/etc/sudoers.d"
register: stat_etc_sudoers_d_ansible
2023-06-10 20:42:37 +00:00
2023-07-13 21:50:24 +00:00
- name: "Verify file /etc/sudoers.d/deploy"
2023-06-10 20:42:37 +00:00
ansible.builtin.assert:
that:
2023-07-13 21:50:24 +00:00
- not stat_etc_sudoers_d_ansible.stat.exists
2023-06-10 20:42:37 +00:00
2023-07-13 21:50:24 +00:00
- name: "Test: ansible authorized_keys"
2023-06-10 20:42:37 +00:00
block:
2023-07-13 21:50:24 +00:00
- name: "Stat file /opt/deploy/.ssh/authorized_keys"
2023-06-10 20:42:37 +00:00
ansible.builtin.stat:
2023-07-13 21:50:24 +00:00
path: "/opt/deploy/.ssh/authorized_keys"
register: stat_opt_ansible_ssh_authorized_keys
2023-06-10 20:42:37 +00:00
2023-07-13 21:50:24 +00:00
- name: "Verify file /opt/deploy/.ssh/authorized_keys"
2023-06-10 20:42:37 +00:00
ansible.builtin.assert:
that:
2023-07-13 21:50:24 +00:00
- not stat_opt_ansible_ssh_authorized_keys.stat.exists