Linux Labs

Automation: Git and Ansible / Stage 4 of 6

Inventory and ad-hoc commands

Not running Starting usually ~20 s
Leave the lesson

Step 4 of 5 · on a machine · 5 min

Root rights and a machine without SSH

Only root writes files in /etc, and in this lesson Ansible logs in as student.

Without the rights the copy module answers FAILED! and “Destination /etc not writable”. The -b option (--become, in the Wiki) runs the module on the machine through sudo, as root. student has sudo without a password, so nothing else is needed:

bash
ansible web -b -m copy -a 'content="x\n" dest=/etc/example.conf'

The machine Ansible runs on can also be described without SSH. The ansible_connection=local variable on a machine's line tells Ansible to run the module right here. That is how localhost is usually written down — so the controlling machine is configured the same way as the others.

Exercise · do it

Configure this machine without SSH

Ansible has to configure the very machine it runs on, without SSH. In ~/ansible-lab add a local group to the inventory with the machine localhost that Ansible reaches without SSH, and with an Ansible ad-hoc command put the file /etc/lab-motd on it with one line “Managed by Ansible”. Run the command once more and look at the answer.

Sign in and start The machine is available after signing in

Goals · 0 of 2

  • Describe this machine in the inventory without SSH not done yet
  • Put the file into /etc with an Ansible ad-hoc command not done yet

Step goals

0 of 2
  • Describe this machine in the inventory without SSH — not done yet
  • Put the file into /etc with an Ansible ad-hoc command — not done yet
Ubuntu 24.04

Step goals

0 of 2
  • Describe this machine in the inventory without SSH — not done yet
  • Put the file into /etc with an Ansible ad-hoc command — not done yet
Loading…