su -
yum install git
git clone https://github.com/tektutor/ansible-aug-2021.git
cd ansible-aug-2021
cd /home/devops/ansible-aug-2021
git pull
su -
yum install -y epel-release
yum install -y ansible
You may now check the version of Ansible installed
ansible --version
The expected output is
[jegan@localhost Ansible]$ ansible --version ansible 2.9.23 config file = /etc/ansible/ansible.cfg configured module search path = ['/home/jegan/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules'] ansible python module location = /usr/lib/python3.6/site-packages/ansibleYou may s executable location = /usr/bin/ansible python version = 3.6.8 (default, Aug 24 2020, 17:57:11) [GCC 8.3.1 20191121 (Red Hat 8.3.1-5)] [jegan@localhost Ansible]$
su -
yum install -y yum-utils
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
yum install -y docker-ce
su -
yum install -y docker-ce --allowerasing
su -
systemctl enable docker
systemctl start docker
systemctl status docker
To come out of the status command, type 'q'
You may check if you are able to execute docker commands as regular user
docker --version
docker images
su -
usermod -aG docker devops
sudo su devops
docker images
ssh-keygen
The expected output is shown below
Generating public/private rsa key pair. Enter file in which to save the key (/home/devops/.ssh/id_rsa): Created directory '/home/devops/.ssh'. Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /home/devops/.ssh/id_rsa. Your public key has been saved in /home/devops/.ssh/id_rsa.pub. The key fingerprint is: SHA256:zJM9Xq61M4HQ31aBkDPqFff37hr6iCfeF8dLJCd0E7I devops@localhost.localdomain The key's randomart image is: +---[RSA 3072]----+ | .o....| | = +o+ | | .. *Eo o| | o.+.. o +o| | S.+o..=oo| | +.+o +.+| | . ooo+.| | .=++.o.| | .+o==oo.| +----[SHA256]-----+ [devops@localhost ~]$
cd /home/devops/ansible-aug-2021
git pull
cd Day1/ubuntu-ansible
cp ~/.ssh/id_rsa.pub authorized_keys
docker build -t tektutor/ansible-ubuntu .
You may optionally change 'tektutor' startup name with your organization name.
docker images
The expected output is
[jegan@localhost ubuntu-ansible]$ docker images REPOSITORY TAG IMAGE ID CREATED SIZE tektutor/ansible-ubuntu latest fbd15f46e99a 14 seconds ago 220MB ubuntu 16.04 38b3fa4640d4 13 days ago 135MB [jegan@localhost ubuntu-ansible]$
docker run -d --name ubuntu1 --hostname ubuntu1 -p 2001:22 -p 8001:80 tektutor/ansible-ubuntu
docker run -d --name ubuntu2 --hostname ubuntu2 -p 2002:22 -p 8002:80 tektutor/ansible-ubuntu
docker ps
The expected output is
[jegan@localhost Day1]$ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 9d46ec6d3a5d tektutor/ansible-ubuntu "/usr/sbin/sshd -D" 7 seconds ago Up 5 seconds 0.0.0.0:2002->22/tcp, :::2002->22/tcp, 0.0.0.0:8002->80/tcp, :::8002->80/tcp ubuntu2 aa5a4350bc75 tektutor/ansible-ubuntu "/usr/sbin/sshd -D" 20 seconds ago Up 18 seconds 0.0.0.0:2001->22/tcp, :::2001->22/tcp, 0.0.0.0:8001->80/tcp, :::8001->80/tcp ubuntu1
ssh -p 2001 root@localhost
exit
ssh -p 2002 root@localhost
exit
When it prompts with the question, you need to type yes
Are you sure, do you want to continue connecting yes/no?
The expected output is shown below
[jegan@localhost Day1]$ ssh -p 2001 root@localhost The authenticity of host '[localhost]:2001 ([::1]:2001)' can't be established. ECDSA key fingerprint is SHA256:irBMfGdAaC2ufLDoygathering=explicit0KZsb5D33z7eqtF/+lv30OxHIY. Are you sure you want to continue connecting (yes/no/[fingerprint])? yes Warning: Permanently added '[localhost]:2001' (ECDSA) to the list of known hosts. Welcome to Ubuntu 16.04.7 LTS (GNU/Linux 4.18.0-240.el8.x86_64 x86_64) * Documentation: https://help.ubuntu.com * Management: https://landscape.canonical.com * Support: https://ubuntu.com/advantage The programs included with the Ubuntu system are free software; the exact distribution terms for each program are described in the individual files in /usr/share/doc/*/copyright. Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by applicable law.
Delete the file that errors out, for example
rm -f /home/devops/ansible-aug-2021/Day1/ubuntu-ansible/authorized_keys
git pull
cd Day1
ansible -i inventory -m ping
The expected output is shown below
[jegan@localhost Ansible]$ cd Day1 [jegan@localhost Day1]$ ls inventory ubuntu-ansible [jegan@localhost Day1]$ pwd /home/jegan/Ansible/Day1 [jegan@localhost Day1]$ ls -l total 4 -rw-rw-r--. 1 jegan jegan 218 Aug 9 00:30 inventory drwxrwxr-x. 2 jegan jegan 47 Aug 8 23:53 ubuntu-ansible [jegan@localhost Day1]$ ansible -i inventory all -m ping ubuntu2 | SUCCESS => { "ansible_facts": { "discovered_interpreter_python": "/usr/bin/python3" }, "changed": false, "ping": "pong" } ubuntu1 | SUCCESS => { "ansible_facts": { "discovered_interpreter_python": "/usr/bin/python3" }, "changed": false, "ping": "pong" } [jegan@localhost Day1]$
- Ansible Creates a temp directory in the ACM and on the Ansible Node(s).
- Ansible then copies the ansible module from ACM into the ACM temp folder and paste all the python inclues inline in the same python script.
- Using sftp/scp, Ansible then copies from the python script from ACM temp to Ansible Node temp folder.
- Ansible gives execute permission to the Python script.
- Executes the Python script on the Ansible Nodes and captures the output from the remote machines.
- Cleans up by deleting the temp folder on the ansible remote machines.
- Gives a summary of output in the ACM.
cd ~/ansible-aug-2021
git pull
cd Day1
ansible-playbook -i inventory ping.yml
cd ~/ansible-aug-2021
git pull
cd Day1
ansible-playbook ping.yml
cd ~/ansible-aug-2021
git pull
cd Day1/centos-ansible
cp ~/.ssh/id_rsa.pub authorized_keys
docker build -t tektutor/ansible-centos .
docker images
docker run -d --name centos1 --hostname centos1 -p 2003:22 -p 8003:80 tektutor/ansible-centos
docker run -d --name centos2 --hostname centos2 -p 2004:22 -p 8004:80 tektutor/ansible-centos
docker ps
ssh -p 2003 root@localhost
exit
ssh -p 2004 root@localhost
exit
cd ~/ansible-aug-2021
git pull
cd Day1
ansible -i hosts all -m ping
cd ~/ansible-aug-2021
git pull
cd Day1/AnsibleRecommendedDirStructure
ansible all -m ping