Lab 2 - Solution

Mandatory

Create the Ansible Configuration

  • Connect to your srv.<firstname>.lab as ansible user

  • Switch into your git repo /home/ansible/training

  • Create a ansible.cfg file and configure

    • inventory path to hosts
    • enable become
vi ansible.cfg

# file: ansible.cfg
[defaults]
inventory = hosts

[privilege_escalation]
become = True

Create a static inventory

  • Create a hosts file

  • add all your servers to the inventory file

    • web1.<firstname>.lab
    • web2.<firstname>.lab
    • db.<firstname>.lab
vi hosts

# file: hosts
web1.firstname.lab
web2.firstname.lab
db.firstname.lab

Run some Ansible commands

  • Run uname -a on all servers
  • Run whoami on all servers
ansible -a "uname -a" all

ansible -a "whoami" all

Commit your changes

  • add all files to your git repo and commit it
git add hosts
git add ansible.cfg
git commit -m 'added inventory and ansible config'

Optional

Run whoami as ansible user

ansible -a "whoami" --become-user=ansible all

Try out ansible-doc

  • print out all available modules
ansible-doc -l
  • have a look at the ping module
ansible-doc ping