Posts

Chapter3: How to run an Ansible Playbook on Linux target (s); in 5 easy steps

Image
Objective: To run a play (set of tasks) on a remote Linux target host. We will use a RedHat Enterprise Linux instance created on Amazon EC2, for this exercise. Prerequisites: 1. You have setup Ansible Control Machine. Refer Chapter-1 otherwise. 2. You have a Linux instance to use as target host. Refer to my blogpost to create one on Amazon EC2 and choose a RHEL AMI (Amazon Machine Image). Step-1: This step is run on the Control Machine . We have to first setup trust between Control Machine and Target. Otherwise you cannot reach the target and will see the following error. On the control machine , generate an SSH key using ssh-keygen. Use the ssh-keygen command. Give the file name id_rsa to save the key in. Your public key will be saved in file id_rsa.pub Check the content of the public key file id_rsa.pub . Step-2:   This step is run on the target host . Login to your target Linux host using PuTTY. Open .ssh/authorized_keys file. Copy the p...

Chapter-2: How to write a simple YAML Playbook to run on Localhost, in 2 easy steps

Image
'Playbook' is Ansible's instruction manual. It has the list of tasks to be executed on the target(s). It is written in YAML. 'Inventory' is a list of hosts that are target computers where the tasks are run. Objective: In this chapter we will write a simple playbook to run on localhost. Prerequisites: 1. You have set up the Ansible Control Machine. Refer Chapter-1 otherwise. Step1: Create a new YAML file as shown in the screenshot. Name it conveniently as local_playbook.yml . I used vi editor.             NOTE: Carefully follow the indentation so the YAML parser doesn't complain.             We can discuss YAML syntax and indentation requirements later. What we wrote above is a play . We are about to run it on localhost. We are executing two tasks in this play; one executes native shell command to fetch current date. The other executes another native shell command to fetch hostname. Step2: From the c...

Chapter1: How to deploy Ansible on a Linux instance, in 3 easy steps

Image
Objective: To install Ansible on a Linux instance and turn it into Ansible Control Machine. As I don't have physical machines to try this out, I am going to use an Amazon EC2 instance. Prerequisites:  1. A Linux instance (preferably Red Hat) with Python installed. Refer to my blogpost to create a Linux instance on AWS cloud. At the time of this writing, AWS offers a RHEL AMI with Python 2.7.x pre-installed. 2. Ensure the private key pair for that instance is saved locally and converted to .ppk file so you can use PuTTY to connect to it. Refer to my blogpost . Step-1: Login to your RHEL instance on Amazon EC2. AWS may limit you to login as ec2-user. But that is fine. You can run installs with sudo Step-2: To pull Ansible from the weblink, run the command: sudo rpm -Uvh https://d1.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm Step-3: Install and check version. sudo yum -y install ansible