Ansible contd
using modules
- Ansible has lots of modules Refer Here
- Using Module
<module-name>:
<parameter-1-name>: <value>
...
<state>: <desired state>
- Refer paramters section in module documentation and fill the values
Activity 1: Install Nginx
- Finding Manual steps: Refer Here
sudo apt update
sudo apt install nginx
- Testing manual steps
- Find module for every manual step
- Create a Playbook
- Refer Here for the changes done
- Lets perform syntax check

- Lets execute dry run (doesnot work in all cases)

- Now lets execute the playbook

- Navigate to public ip

Activity 2: Install Apache
- Overview

- Manual steps
# ubunu
sudo apt update
sudo apt install apache2 -y
sudo systemctl enable apache2
sudo systemctl start apache2
# redhat steps
sudo dnf install httpd
sudo systemctl enable httpd.service
sudo systemctl start httpd.service
- Daemon: This is an application designed to run in background. To ensure this application starts when your machine is started we have to enable the daemon/service
sudo systemctl => control daemons
sudo service => control daemons
- Daemon in ubuntu: generally after install softwares the daemon is mostly enabled
- Daemon in Redhat: we have to enable and start the daemon or service
-
Execute the ansible playbook
-
Problems to be addressed:
- redhat 9 issue
- why check doesn’t work all the time
adhoc command
- Ansible automation can be executed using two approaches
- imperative: using ansible commands (adhoc)
- declrative: writing playbooks
- Adhoc command: Refer Here
ansible -i <inventory> -m "<module name>" -a "parameter1=value1 parameter2=value2"
- Adhoc command for uninstallign ansible
ansible -i hosts -m apt -a "name=nginx purge=true state=absent"
