To help speed up the process of configuration management or orchestration
- For config management we use Ansible
- For orchestration we use terraform
- By creating a script in YML using Ansible
- Many servers running all around the world in the cloud
-
- YMAL = we can create one file in the controller and define what items we want to install in one file, and then we would like to update both servers (VMs with the relevant things)
- Automation tool for configuration management
-
its simple, agentless, IT automation tools
-
Agentless? = we do not need to install ansible in app, or db servers, we just need it in the controller and connectivity from controller to the servers
-
Allows us to connect to any server in the world using ssh
- connect using ssh = related to simplicity
- 3 VMs- 1 will be a virtual controller , app and db
- Python in both VM App and VM db (ubuntu 16.04 has python configured already)
- Saves time, open source, makes config management predictable, cost effective
- it automates the process of configuration management
- open source = we dont need to buy it = provides detailed documentation online for ease of use
- does not diffrentiate between different providers as long as you have the correct script written
Step 3: ssh into all VMs and run sudo apt-get update
to check the connectivity of internet for all 3
- we will use AWS for this
- therefore need to install Ansible on chosen controller
- look at the file system on controller using tree
- consider how to create hoest entries
- tell controller which IPs to communicate with
vagrant ssh aws
sudo apt-get install software-properties-common -y
sudo apt-add-repository ppa:ansible/ansible
sudo apt-get update
sudo apt-get install ansible -y
sudo apt-get install tree
cd /etc/ansible
and enter tree
command
ping 192.168.33.11
ping 192.168.33.10
- should respond with pong if successful
[web]
192.168.33.10 ansible_connection=ssh ansible_ssh_user=vagrant ansible_ssh_pass=vagrant
[db]
192.168.33.11 ansible_connection=ssh ansible_ssh_user=vagrant ansible_ssh_pass=vagrant
- we have told the hosts file that these are the 2 servers that we would like ansible controller to communicate with
ssh vagrant@IP
sudo apt-get update
exit
- do this to ensure you can connect to the VMs and they have internet connectivity
sudo ansible all -m ping
- checks network connectivity
** ERROR = AWS VM WAS CORRUPT SO HAD TO USE WEB AS THE CONTROLLER AND AWS AS WEB ** ** HAD TO DELETE ANSIBLE FOLDER MANUALLY IN VAGRANT AND REINSTALL ON THE WEB VM IN ORDER TO USE AS CONTROLLER
echo /home/vagrant/.ansible/tmp/ansible-tmp-15
- its easy, fast, robust with one command we can find out space, what is already installed etc
ansible aws -a "date"
ansible db -a "uname -a"
ansible all -a "ls -a"
ansible all -m shell -a "ls -a"
ansible all -m shell -a "free"
ansible all -m shell -a 'uptime' --become
ansible all -m shell -a "env"
[displays all env variables]
ansible all -m shell -a "ip addr"
[displays all ip addresses]
ansible all -m shell -a 'ps -ef'
ansible all -m shell -a 'ps -a'
ansible all -m shell -a "ifconfig"
ansible db -m shell -a "hostname -I"
[returns private and public ip nothing else]
- YAML (Yes another markup language) .yml or .ymal
- Units of scripts which describe work to configure server/servers
---
starts with 3 dashes- indentation is super important in YAML
- for configuration management - install programs, update programs etc
- why over ad hoc commands? it automates the tasks in multiple servers
- in ansible folder create a new file
sudo nano nginx install_nginx_on_web.yml
- Edit the file
# this is YAML file to install nginx in our web server
---
# where do we want to install
- hosts: aws
# get the facts
gather_facts: yes
# work from root user
become: true
# what do we want ansible to do for us in this playbook?
tasks:
- name: Install nginx
# telling ansible which package to install and the state of it - states are: present/absent
apt: pkg=nginx state=present
-
ansible-playbook install_nginx_on_web.yml
-
Run the IP given (web VM) on browser