Ansible Training Notes – 22 July 2023

Limited Time Offer!

For Less Than the Cost of a Starbucks Coffee, Access All DevOpsSchool Videos on YouTube Unlimitedly.
Master DevOps, SRE, DevSecOps Skills!

Enroll Now
What is Ansible?
	- config 	mgmt 		tool
			server(s)

	- deploy mgmt 

	- python

	- from redhat

	release
		ansible	- cmd - free
		tower - web - paid - support
		awx - web  - free - no supprt
What config?
	file
	dir
	package
	services
	cmd
	APt

Why Ansible?
-------------------------------------------
	We want to manage config of 100(s) server parrell...
	1 deployment in 1 machine takes 10 mins
	1 deployment in 100 machine takes 10 mins

	shell - linux
	ps - windows
	ansible platform inde

	python - java 
	
	ansible is easy 
			for read - write - test - debug - extend - share

Others -- chef - puppet - salt - cfengine
===================================================
Ansible arch aka how this works?

Human -->  ACS --> ARS (S)


	ACS - 		=== 		ARS
	---------------
	Ansible				NO
	Linux				ANY
	Python				LINUX - python
					windows - ps3 + dotnet

		------------------------Linux -- SSH
		------------------------ Win --- winrm
=====================================================
1. ACS - Install Ansible
------------------------
- executable
- modules	- A python code --> Running in ARS with param. copy [ src  & dest ]
								apt [ install & git ]
		https://docs.ansible.com/ansible/2.9/modules/list_of_all_modules.html
		https://docs.ansible.com/ansible/2.9/modules/modules_by_category.html
		
- plugins	- A python code	--> Adding feature in Ansible
- configfile	- If you want to overirde harding of executable variables - can specify in configfile

$ sudo apt update
$ sudo apt install software-properties-common
$ sudo add-apt-repository --yes --update ppa:ansible/ansible
$ sudo apt install ansible
https://docs.ansible.com/ansible/latest/installation_guide/installation_distros.html#installing-ansible-on-ubuntu

2. ACS - inventory
		LIST OF IP ADD|Hostname of ARS
			CMD
			file
			script
3. ACS - playbook
		yaml
		play
	
		Play
			Hosts: group from inventory
			Tasks:
				Module and its param
				Module and its param
				Module and its param
				Module and its param


===============================================================

Project - Setup a webserver using ansible...Deploy a webserver in 100s of box
----------------------------------------------------------

Step 1 - Install webserver apache2 in ubuntu
		apt {name=apache2 state=latest}
		apt install apache2
Step 2 - Copy a packages
		copy {src=index.html dest=/var/www/html
Step 3 - Start a web service
		service name=apach2 state=started
		service of linux

copy a file in 1 machine
-------------------------
cmd		== ansible adhoc cmd
script		== playbook

1 module in 1 machine ---- adhoc cmd
1 module in 100 machine ---- adhoc cmd wih inventory

100 module in 1 machine ---- playbook
100 module in 100 machine ---- playbook wih inventory
================================================
anible

anible-playbook
==================================================
ansible localhost -m apt -a"name=apache2 state=latest"
ansible localhost -m copy -a"src=index.html dest=/var/www/html"
ansible localhost -m service -a"name=apache2 state=started"


18.212.4.186
44.208.165.223


ansible all -i inventory -m apt -a"name=apache2 state=latest"
ansible all -i inventory -m copy -a"src=index.html dest=/var/www/html"
ansible all -i inventory -m service -a"name=apache2 state=started"

all == group build in

ansible all -i inventory -m apt -a"name=apache2 state=latest" -u ubuntu --key-file=node.pem -b 
ansible all -i inventory -m copy -a"src=index.html dest=/var/www/html" -u ubuntu --key-file=node.pem -b
ansible all -i inventory -m service -a"name=apache2 state=started" -u ubuntu --key-file=node.pem -b

[web]
18.212.4.186
44.208.165.223

[db]
10.2.2.2
10.2.2.2
10.2.2.4

ansible web -i inventory -m apt -a"name=apache2 state=latest" -u ubuntu --key-file=node.pem -b 
ansible web -i inventory -m copy -a"src=index.html dest=/var/www/html" -u ubuntu --key-file=node.pem -b
ansible web -i inventory -m service -a"name=apache2 state=started" -u ubuntu --key-file=node.pem -b

ansible web -i inventory -m apt -a"name=apache2 state=latest" -u ubuntu -k -b 
ansible web -i inventory -m copy -a"src=index.html dest=/var/www/html" -u ubuntu -k -b 
ansible web -i inventory -m service -a"name=apache2 state=started" -u ubuntu -k -b 


Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x