provision_ansible_user/molecule/default/tests/test_default.py

30 lines
974 B
Python
Raw Normal View History

2023-03-20 23:05:21 +00:00
"""Role testing files using testinfra."""
def test_hosts_file(host):
"""Validate /etc/hosts file."""
etc_hosts = host.file("/etc/hosts")
assert etc_hosts.exists
assert etc_hosts.user == "root"
assert etc_hosts.group == "root"
2023-03-20 23:05:21 +00:00
def test_ansible_user_group(host):
"""Validate consul user and group."""
ansible_group = host.group("ansible")
ansible_user = host.user("ansible")
assert ansible_group.exists
assert ansible_user.exists
assert ansible_user.group == "ansible"
assert ansible_user.shell == "/bin/bash"
def test_ansible_sudoer(host):
"""Validate that ansible user is not sudoer"""
etc_sudoers_d_ansible = host.file("/etc/sudoers.d/ansible")
assert not etc_sudoers_d_ansible.exists
def test_ansible_no_ssh(host):
"""Validate that ansible user has no authorized_keys"""
opt_ansible_authorized_keys = host.file("/opt/ansible/.ssh/authorized_keys")
assert not opt_ansible_authorized_keys.exists