Ansible contd
Activity 3 : Installing php on apache
- Refer Here for manual steps
- Note: we will be skipping mysql.
- Manual steps for ubuntu
sudo apt update
sudo apt install apache2 -y
sudo systemctl enable apache2
sudo systemctl start apache2
sudo apt install php libapache2-mod-php php-mysql
sudo systemctl restart apache2
# create a file in /var/www/html/info.php with content <?php phpinfo(); ?>
sudo systemctl restart apache2
- Lets write a playbook for this.
- Refer Here for the first version of playbook with inventory and variables added.
- Ansible handlers Refer Here
- Refer Here for the changes in inventory and variables
Ansible inventory
- Inventory is list of hosts
- Inventory consists of groups and hosts
- Inventory can be written in two formats
- ini
- yaml
- ini
[group-1]
host-1
host-2
[group-2]
host-3
host-4
[experiment-group]
host-1
host-3
- Yaml
---
group-1:
hosts:
host-1:
host-2
group-2
hosts:
host-3
host-4
experiment-group:
hosts:
host-1
host-3
- we have a host where we need to add a variable package with value apache2
- in ini format
[webservers]
192.168.0.11 package=apache2
- in yaml format
---
webservers:
hosts:
192.168.0.11:
package=apache2
*
Ansible variables
- Ansible variables can be created in different locations
- inventory:
- directly in inventory
- relative to inventory
- playbook
- pass variables during execution
- inventory:
