2 minutes
Ansible Set Up and Configuration in AWS EC2 Instance
For this set up, we will be requiring the following:
- 1 RHEL EC2 Instance for the master/management node
- 1 RHEL EC2 Instance for the Unix host
Install Python and Git in both EC2 Instances:
$ sudo yum install python3 $ sudo yum install git
Perform update
Install pip
$ sudo yum -y install python3-pip
Install ansible
$ sudo pip3 install ansible
Create new
ansible
user for all hosts (master and host)$ sudo useradd ansible ; echo "" | passwd --stdin ansible
Please refer from the AWS documentation on managing users:
https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/managing-users.html
Modify the entry in sudoers file
/etc/sudoers
for the ansible user for password-less sudo access:$ sudo visudo
Add this line at the end of the file.
ansible ALL=(ALL) NOPASSWD: ALL
Generate ssh key in the ansible master server
Copy the public key to remote or host server as ansible user. You may need to create the .ssh directory and the authorized_keys if they don’t exist yet.
Change the permissions of the keys in the master server and authorized_keys in the host server.
$ chmod 600 id_rsa.pub $ chmod 600 id_rsa $ chmod 600 authorized_keys
Verify the login to host from the master server.
$ ssh ansible@hostserver
Create the ansible inventory file, the default is
/etc/ansible/hosts
.Use the ping module to test ansible and you should see similar output below for a successful host connection