Skip to content

Example 1

hosts.yml

centos:
  hosts:
    provisioner:
      ansible_connection: local
    centos1:
      ansible_host: '192.168.77.22'
      ansible_port: 2345
ubuntu:
  hosts:
    ubuntu1:
      ansible_host: '192.168.77.23'

Tip

The file module is widely used alongside the copy and template modules for performing operations on files, symlinks and directories. Check out the module's official documentation or run

ansible-doc file

Execute the following command

ansible centos1 -m file -a 'path="/etc/foo.conf" state=touch'

What is the expected output of the command?

The command should fail (with Permission denied) as the vagrant user does not have write permissions inside the /etc directory.

Bonus round

Using your knowledge of privilege escalation in Ansible propose a solution that would make the file creation possible.