Automation with Ansible Part 1 - nicolas-tullio/Tech-Journal GitHub Wiki

Networking

  • controller 10.0.5.90
  • ansible1 10.0.5.91
  • ansible2 10.0.5.92
  • create deployer account on all machines and give it sudo
  • Add in the DNS records

Ansible

  • On controller run: > sudo apt install ansible sshpass python3-paramiko
  • On each machine create a file in /etc/sudoers.d/sys265
  • In this file write:

deployer[tab]ALL=(ALL)[tab]NOPASSWD: ALL

  • On controller create an RSA keypair with a passphrase:

ssh-keygen -t rsa -C "sys265" eval $(ssh-agent) ssh-add -t 14400 ssh-copy-id deployer@ansible1

Testing ansible

> mkdir -p /home/deployer/ansible/roles
  • cd into ansible and run: > echo ansible1-nicolas >> inventory.txt and then run echo ansible2-nicolas >> inventory.txt
  • Then to make sure it works run: > ansible all -m ping -i inventory.txt
  • Add a tag into the inventory.txt file above the machines you want in the tag write [tag]

    ansible tag -m ping -i inventory.txt

Playbook installation

> ansible-galaxy install user.role -p roles/
  • In roles create a role.yml file
  • Execute the playbook: ansible-playbook -i inventory.txt roles/role.yml