import os import testinfra.utils.ansible_runner import warnings warnings.filterwarnings("ignore", category=DeprecationWarning) testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( os.environ['MOLECULE_INVENTORY_FILE'] ).get_hosts('all') def test_sudoers_file(host): sudoers = host.file("/etc/sudoers") assert sudoers.exists assert sudoers.user == "root" assert sudoers.group == "root" assert sudoers.mode == 0o440 def test_sudoers_content(host): sudoers = host.file("/etc/sudoers") assert sudoers.contains("/sbin:/bin:/usr/sbin:/usr/bin") assert sudoers.contains("!visiblepw") assert sudoers.contains("XAUTHORITY")