Ansible Notes – Aug Batch Online – Notes – Day -2

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
Project - Setup a Webserver

IMPORTANT - YOU MUST KNOW EACH Manual STEPS of What you are coding

Psucode - ubuntu
=======================
Step 1 - Install apache in ubuntu	apt
Step 2 - COpy index.html in ubuntu	copy
Step 3 - Start a web service		service

-----------------------------------------------

Every module you would STATE param - which would decide wt to do?

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

Inventory
	is LIST of IP add of ARS	
	Can be passed on 
		CMD
			18.208.198.47,172.22.240.232 WRONG
			18.208.198.47,172.22.240.232, RIGHT
		FILE
		SCRIPT

Authentication - How to login? ====> Authorization - Wt ur allowed to do?	

ansible -i 18.208.198.47,172.22.240.232, -m apt -a"name=apache2 state=present" -u ubuntu -k -b
ansible -i 18.208.198.47,172.22.240.232, -m copy -a"src=index.html dest=/var/www/html/index.html" -u ubuntu -k -b
ansible -i 18.208.198.47,172.22.240.232, -m service -a"name=apache2 state=started"  -u ubuntu -k -b
 
GROUP
===========================
all

ansible all -i 18.208.198.47,172.22.240.232, -m apt -a"name=apache2 state=present" -u ubuntu -k -b
ansible all -i 18.208.198.47,172.22.240.232, -m copy -a"src=index.html dest=/var/www/html/index.html" -u ubuntu -k -b
ansible all -i 18.208.198.47,172.22.240.232, -m service -a"name=apache2 state=started"  -u ubuntu -k -b

root@DESKTOP-94AUF6U:~# ansible all -i 18.208.198.47,172.22.240.232, -m apt -a"name=apache2 state=present" -u ubuntu -k -b
SSH password:
172.22.240.232 | FAILED! => {
    "msg": "Using a SSH password instead of a key is not possible because Host Key checking is enabled and sshpass does not support this.  Please add this host's fingerprint to your known_hosts file to manage this host."
}
18.208.198.47 | FAILED! => {
    "msg": "Using a SSH password instead of a key is not possible because Host Key checking is enabled and sshpass does not support this.  Please add this host's fingerprint to your known_hosts file to manage this host."

First 
Run following commands in each ARS
  8  apt update
    9  clear
   10  ls
   11  apt install sshpass

Second
Modify /etc/ansible/ansible.cfg in ACS

[defaults]
host_key_checking = False



root@DESKTOP-94AUF6U:~# ansible all -i 18.208.198.47,172.22.240.232, -m apt -a"name=apache2 state=present" -u ubuntu -k -b
SSH password:
172.22.240.232 | UNREACHABLE! => {
    "changed": false,
    "msg": "Failed to create temporary directory. In some cases, you may have been able to authenticate and did not have permissions on the target directory. Consider changing the remote tmp path in ansible.cfg to a path rooted in \"/tmp\", for more error information use -vvv. Failed command was: ( umask 77 && mkdir -p \"` echo /home/ubuntu/.ansible/tmp `\"&& mkdir \"` echo /home/ubuntu/.ansible/tmp/ansible-tmp-1692676517.394163-1957-255011346482889 `\" && echo ansible-tmp-1692676517.394163-1957-255011346482889=\"` echo /home/ubuntu/.ansible/tmp/ansible-tmp-1692676517.394163-1957-255011346482889 `\" ), exited with result 1",
    "unreachable": true
}
18.208.198.47 | UNREACHABLE! => {
    "changed": false,
    "msg": "Failed to connect to the host via ssh: Warning: Permanently added '18.208.198.47' (ED25519) to the list of known hosts.\r\nubuntu@18.208.198.47: Permission denied (publickey).",
    "unreachable": true
}

inventory
-------------------------
18.208.198.47
172.22.240.232

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


inventory
-------------------------

[web]
18.208.198.47
172.22.240.232

[db]
18.208.198.4
172.22.240.2d


ansible web -i inventory -m apt -a"name=apache2 state=present" -u ubuntu -k -b
ansible web -i inventory -m copy -a"src=index.html dest=/var/www/html/index.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