2023-07-13 21:50:24 +00:00
|
|
|
---
|
|
|
|
- name: Verify
|
|
|
|
hosts: all
|
2023-12-03 17:10:56 +00:00
|
|
|
gather_facts: true
|
|
|
|
become: true
|
2023-07-13 21:50:24 +00:00
|
|
|
tasks:
|
2023-07-17 21:12:30 +00:00
|
|
|
- name: "Test: ubuntu user and group"
|
2023-07-13 21:50:24 +00:00
|
|
|
block:
|
|
|
|
- name: "Getent user ansible"
|
|
|
|
ansible.builtin.getent:
|
|
|
|
database: passwd
|
2023-07-17 21:12:30 +00:00
|
|
|
key: ubuntu
|
2024-02-05 21:51:23 +00:00
|
|
|
register: ednz_cloud_management_user
|
2023-07-13 21:50:24 +00:00
|
|
|
|
2023-07-17 21:12:30 +00:00
|
|
|
- name: "Getent group ubuntu"
|
2023-07-13 21:50:24 +00:00
|
|
|
ansible.builtin.getent:
|
|
|
|
database: group
|
2023-07-17 21:12:30 +00:00
|
|
|
key: ubuntu
|
2024-02-05 21:51:23 +00:00
|
|
|
register: ednz_cloud_management_group
|
2023-07-13 21:50:24 +00:00
|
|
|
|
2023-07-17 21:12:30 +00:00
|
|
|
- name: "Verify ubuntu user and group"
|
2023-07-13 21:50:24 +00:00
|
|
|
ansible.builtin.assert:
|
|
|
|
that:
|
2024-02-05 21:51:23 +00:00
|
|
|
- not ednz_cloud_management_user.failed
|
|
|
|
- not ednz_cloud_management_group.failed
|
|
|
|
- "'ubuntu' in ednz_cloud_management_user.ansible_facts.getent_passwd.keys()"
|
|
|
|
- "'/home/ubuntu' in ednz_cloud_management_user.ansible_facts.getent_passwd['ubuntu']"
|
|
|
|
- "'/bin/bash' in ednz_cloud_management_user.ansible_facts.getent_passwd['ubuntu']"
|
|
|
|
- "'ubuntu' in ednz_cloud_management_group.ansible_facts.getent_group.keys()"
|
2023-07-13 21:50:24 +00:00
|
|
|
|
2023-07-17 21:12:30 +00:00
|
|
|
- name: "Test: ubuntu sudo permissions"
|
2023-07-13 21:50:24 +00:00
|
|
|
block:
|
2023-07-17 21:12:30 +00:00
|
|
|
- name: "Stat file /etc/sudoers.d/ubuntu"
|
2023-07-13 21:50:24 +00:00
|
|
|
ansible.builtin.stat:
|
2023-07-17 21:12:30 +00:00
|
|
|
path: "/etc/sudoers.d/ubuntu"
|
|
|
|
register: stat_etc_sudoers_d_ubuntu
|
2023-07-13 21:50:24 +00:00
|
|
|
|
2023-07-17 21:12:30 +00:00
|
|
|
- name: "Slurp file /etc/sudoers.d/ubuntu"
|
2023-07-16 20:04:43 +00:00
|
|
|
ansible.builtin.slurp:
|
2023-07-17 21:12:30 +00:00
|
|
|
src: "/etc/sudoers.d/ubuntu"
|
|
|
|
register: slurp_etc_sudoers_d_ubuntu
|
2023-07-16 20:04:43 +00:00
|
|
|
|
2023-07-17 21:12:30 +00:00
|
|
|
- name: "Verify file /etc/sudoers.d/ubuntu"
|
2023-07-13 21:50:24 +00:00
|
|
|
ansible.builtin.assert:
|
|
|
|
that:
|
2023-07-17 21:12:30 +00:00
|
|
|
- stat_etc_sudoers_d_ubuntu.stat.exists
|
|
|
|
- stat_etc_sudoers_d_ubuntu.stat.isreg
|
|
|
|
- stat_etc_sudoers_d_ubuntu.stat.pw_name == 'root'
|
|
|
|
- stat_etc_sudoers_d_ubuntu.stat.gr_name == 'root'
|
|
|
|
- stat_etc_sudoers_d_ubuntu.stat.mode == '0440'
|
|
|
|
- "'ubuntu ALL=NOPASSWD:SETENV: ALL' in (slurp_etc_sudoers_d_ubuntu.content|b64decode)"
|
2023-07-13 21:50:24 +00:00
|
|
|
|
2023-07-17 21:12:30 +00:00
|
|
|
- name: "Test: ubuntu authorized_keys"
|
2023-07-13 21:50:24 +00:00
|
|
|
block:
|
2023-07-17 21:12:30 +00:00
|
|
|
- name: "Stat file /home/ubuntu/.ssh/authorized_keys"
|
2023-07-13 21:50:24 +00:00
|
|
|
ansible.builtin.stat:
|
2023-07-17 21:12:30 +00:00
|
|
|
path: "/home/ubuntu/.ssh/authorized_keys"
|
|
|
|
register: stat_home_ubuntu_ssh_authorized_keys
|
2023-07-13 21:50:24 +00:00
|
|
|
|
2023-07-17 21:12:30 +00:00
|
|
|
- name: "Slurp file /home/ubuntu/.ssh/authorized_keys"
|
2023-07-16 20:04:43 +00:00
|
|
|
ansible.builtin.slurp:
|
2023-07-17 21:12:30 +00:00
|
|
|
src: "/home/ubuntu/.ssh/authorized_keys"
|
|
|
|
register: slurp_home_ubuntu_ssh_authorized_keys
|
2023-07-16 20:04:43 +00:00
|
|
|
|
2023-07-17 21:12:30 +00:00
|
|
|
- name: "Verify file /home/ubuntu/.ssh/authorized_keys"
|
2023-07-13 21:50:24 +00:00
|
|
|
ansible.builtin.assert:
|
|
|
|
that:
|
2023-07-17 21:12:30 +00:00
|
|
|
- stat_home_ubuntu_ssh_authorized_keys.stat.exists
|
|
|
|
- stat_home_ubuntu_ssh_authorized_keys.stat.isreg
|
|
|
|
- stat_home_ubuntu_ssh_authorized_keys.stat.pw_name == 'ubuntu'
|
|
|
|
- stat_home_ubuntu_ssh_authorized_keys.stat.gr_name == 'ubuntu'
|
|
|
|
- stat_home_ubuntu_ssh_authorized_keys.stat.mode == '0600'
|
|
|
|
- "'ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIClfmTk73wNNL2jwvhRUmUuy80JRrz3P7cEgXUqlc5O9 ubuntu@instance' in (slurp_home_ubuntu_ssh_authorized_keys.content|b64decode)"
|