DevOps Classroom Series – 26/Dec/2020
Solving the Scenario
- Exercise: Now try Writing an ansible playbook for install tomcat8 on ubuntu and centos
- Solution:
- We have configured 3 ansible nodes
- 2 centos server with python 2.7
- 1 ubuntu server with python 3.7
- All the machines have a user ‘ansible’ configured for password less authentication
- So first lets verify inventory Refer Here
- We have ran ansible ping adhoc command
- ansible has predefined inventory parameters which can change ansible behavior for a node or group of nodes
- ansible_host: This is DNS name
- ansible_port: port for ssh (default will be 22)
- ansible_user: Specifies the username that ansible will connect to node with
- ansible_ssh_private_key_file: SSH private key file used to connect to node
- ansible_python_interpreter: used to set manual path of python on node
- ansible_become
- ansible_become_method
- ansible_sudo_pass
- ansible_become_password
- ansible_connection
- ansible_shell_type
- ansible_shell_executable
- ansible_ssh_pass
- Refer Here
- To find some details about nodes we can use the setup module Refer Here
- We can combine facts with ansible conditionals for conditional execution Refer Here
- Refer Here for the changeset
- Now lets try to create a user as mentioned below
sudo useradd -m -U -d /opt/tomcat -s /bin/false tomcat
- Refer Here for the changeset
- Refer Here for the draft playbook with 3 steps of ubuntu automated
- Refer Here for the draft playbook with 3 steps for centos automated
- Exercise:
- Correct the failures in playbook execution
- Try creating only one playbook which does this 3 steps automation in centos and ubuntu
- Observe the behavior of your playbook when it is executed multiple times