1
votes

Im new to Devops and im learning the Ansible as a beginner with AWS EC2 Ubuntu 16.04 LTS.

initially i have launched 2 EC2 instances with SSH port 22 open in security group, i named the instances as Master and Slave.

I ssh'ed into Master Instances when all is up and running. I will list steps one by one as follow

1. I created a user called ansible and issued password

 ubuntu@ip-172-31-17-94:~$ sudo su
    root@ip-172-31-17-94:/home/ubuntu# adduser ansible 
Adding user `ansible' ...
Adding new group `ansible' (1001) ...
Adding new user `ansible' (1001) with group `ansible' ...
Creating home directory `/home/ansible' ...
Copying files from `/etc/skel' ...
Enter new UNIX password: 
Retype new UNIX password: 
passwd: password updated successfully
Changing the user information for ansible
Enter the new value, or press ENTER for the default
    Full Name []: 
    Room Number []: 
    Work Phone []: 
    Home Phone []: 
    Other []: 
Is the information correct? [Y/n] 

2. uncommented PermitRootLogin yes and PasswordAuthentication yes in /etc/ssh/sshd_config and restarted ssh

3.Changed the Visudo file adding root access to ansible user

root@ip-172-31-17-94:/home/ubuntu# visudo 

edited

  # User privilege specification
root    ALL=(ALL:ALL) ALL
ansible ALL=(ALL:ALL) ALL

saved and closed

4.Generated ssh keygen

ansible@ip-172-31-17-94:~$ ssh-keygen -t rsa -b 4096 
Generating public/private rsa key pair.
Enter file in which to save the key (/home/ansible/.ssh/id_rsa): 
Created directory '/home/ansible/.ssh'.
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/ansible/.ssh/id_rsa.
Your public key has been saved in /home/ansible/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:wah0yD9Ngf7hzLIihkEFvNYjPNrzcLubNxGnqFKYrik ansible@ip-172-31-17-94
The key's randomart image is:
+---[RSA 4096]----+
|...    ..        |
| . o ..o .       |
|. + +.o +        |
| B + +ooo.       |
|++o o.oOS.       |
|= = o +.=        |
|.+ * . +         |
|Eo+ +.+          |
|=o .+= .         |
+----[SHA256]-----+

5. Installing Ansible packages

$ sudo apt-get install software-properties-common
$ sudo apt-add-repository ppa:ansible/ansible
$ sudo apt-get update
$ sudo apt-get install ansible

Awesome!.. all is up and ansible is install in master server I issued a command to test the ansible

ansible@ip-172-31-17-94:~$ ansible --version 
ansible 2.3.0.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = Default w/o overrides
  python version = 2.7.12 (default, Nov 19 2016, 06:48:10) [GCC 5.4.0 20160609]

6. Edited the /etc/ansible/hosts and added my slave server private ip (My ec2 are in same subnet in same availability zone ) so i used private Ip

[my]

172.31.29.197 .save and closed

7.ssh'ed in Slave Server and repeated the 1, 2 ,3 steps and logout

8.shh'ed into Master server

local@host $ shh ansible@<Master Ip>

9.Copying public Key to the Slave Server from Master server

ansible@ip-172-31-17-94:~$ ssh-copy-id 172.31.29.197
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/ansible/.ssh/id_rsa.pub"
The authenticity of host '172.31.29.197 (172.31.29.197)' can't be established.
ECDSA key fingerprint is SHA256:qOW0ZktetcpTNmxRsubxn1kcr8egyNmcA5Uk9+oWc7A.
Are you sure you want to continue connecting (yes/no)? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
[email protected]'s password: 

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh '172.31.29.197'"
and check to make sure that only the key(s) you wanted were added 


ansible@ip-172-31-17-94:~$ ssh 172.31.29.197
Welcome to Ubuntu 16.04.2 LTS (GNU/Linux 4.4.0-1013-aws x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

  Get cloud support with Ubuntu Advantage Cloud Guest:
    http://www.ubuntu.com/business/services/cloud

14 packages can be updated.
12 updates are security updates.


Last login: Sat Apr 22 06:27:15 2017 from 42.109.141.238
ansible@ip-172-31-29-197:~$ logout
Connection to 172.31.29.197 closed.

And successfully configured the Mater to Slave password-less ssh connection

Till then i haven't faced any issue. when i issued a command Ansible -m ping all i got an error

172.31.29.197 | FAILED! => {
    "changed": false, 
    "failed": true, 
    "module_stderr": "Shared connection to 172.31.29.197 closed.\r\n", 
    "module_stdout": "/bin/sh: 1: /usr/bin/python: not found\r\n", 
    "msg": "MODULE FAILURE", 
    "rc": 0
}

later when i gooogled i got some chunks i followed listed step by the solution. the solution is i repeated step no.5 from above list in slave server. when issued ansible -m ping from the Master server i got success Message

My question that how to install agent-less anible in a Slave, The main feature of ansible agent-less!

Help me if i missed any of step

1

1 Answers

1
votes

You need to install Python 2 on 172.31.29.197.

Or (in a less likely case) if it is installed in a path different than /usr/bin/python you need to add ansible_python_interpreter parameter pointing to the right executable to your inventory file.