Ansible

ansible.png
Ansible, DevOps

Ansible configuration

Installing and Configuring Ansible on an EC2 Instance STEP 1 : LAUNCH EC2 INSATANCE STEP 2 : CREATE THREE EC2 INSATANCE STEP 3 : NAME OF THE EC2 INSATANCE STEP 4 : SELECT AMAZON LINUX STEP 5 : SELECT THE ARCHITECTURE STEP 6 : SELECT THE INSTANCE TYPE STEP 7 : CREATE THE KEY PAIR STEP 8 : CREATE THE KEY PAIR STEP 9 : SELECT THE KEYPAIR STEP 10 : ALLOW HTTP AND SSH TRAFFIC STEP 11 : LAUNCH INSTANCE STEP 12 : GO TO INSTANCE STEP 13 : RENAME THE INSTANCE STEP 14: CONNECT THE ANSIBLE SERVER INSTANCE STEP 15: INSTALL ANSIBLE IN ANSIBLE SERVER INSTANCE Run the following command in the terminal to install Ansible: $ sudo su – $ yum install ansible -y  (running sudo su – grants you superuser (root) access on the system.) Step 16 : create host.ini , host.pem , playbook.yaml file touch host.ini → Creates an empty inventory file for Ansible hosts. touch host.pem → Creates an empty private key file (likely for SSH authentication). touch playbook.yaml → Creates an empty Ansible playbook file. ls→ Lists the files in the current directory. $ touch host.ini $ touch host.pem $ touch playbook.yaml $ ls Step 17: Copy the vpckey.pem File Content Go to the downloads from your system and search for the key pair here we have created the vpc as keypair file open the pem file and Copy the content of the vpc.pem file that was downloaded while creating the three EC2 instances Select and copy the entire content of the file. Select and copy the entire content of the file.Open a  file (host.pem) to store the copied content $ vi host.pem press on ‘I’ from the keyboard to make it insert mode  by pressing: i Paste the copied content into the host.pem file. Exit insert mode by pressing: Esc Save and close the file by typing “:wq” copy the host.pem file and paste into  /tmp/host.pem $ cp host.pem /tmp/host.pem Change the permission to readable. Step 18: Configure host.ini Open the host.ini file using a text editor. $vi host.ini Enter insert mode by pressing: i [docker] ec2-34-203-225-21.compute-1.amazonaws.com [httpd] ec2-54-86-174-49.compute-1.amazonaws.com [docker:vars] ansible_user=ec2-user ansible_ssh_private_key_file=/tmp/host.pem [httpd:vars] ansible_user=ec2-user ansible_ssh_private_key_file=/tmp/host.pem host 1 public DNS- ec2-34-203-225-21.compute-1.amazonaws.com -dockerhost 2 public DNS – ec2-34-203-225-21.compute-1.amazonaws.com -httpd Exit insert mode by pressing: Esc Save and exit the file: “:wq“ Step 19: Configure Host1 for Docker and Host2 for HTTPD “vi playbook.yaml” It is used to edit the file. Please copy the content above and add it to the playbook.yaml file. – name: Install Docker using Ansible Playbook hosts: docker become: true tasks: – name: Install Docker package package: name: docker state: present – name: Start and enable Docker service service: name: docker state: started enabled: yes – name: Install HTTPD using Ansible Playbook hosts: httpd become: true tasks: – name: Install HTTPD package package: name: httpd state: present – name: Start and enable HTTPD service service: name: httpd state: started enabled: yes Press i to enter “insert mode” and make the necessary changes. After editing, press Esc to exit insert mode. To save the file and exit, type :wq and press Enter. Step 20: Configure Host1 for Docker and Host2 for HTTPD ansible–playbook: Executes an Ansible playbook. -i host.ini: Specifies the inventory file (host.ini) that contains the target hosts for deployment. playbook.yaml: The Ansible playbook file defining the tasks to be executed on the target hosts. $ ansible-playbook -i host.ini playbook.yaml host1 will have Docker installed and running. host2 will have Apache HTTPD installed and running. Now both servers are configured automatically using Ansible! For  more information  Click here  For more information Visit Cloud Institution

ansible.png
Ansible, DevOps

How to Install Ansible on Linux EC2

How to Install Ansible in Linux EC2 Step1 : To launch a new instance, go to the AWS Console and search for EC2. Once you find it, click on EC2, then select “Instances” from the menu. Finally, click on “Launch Instances” to start the process. Step 2: In the “Name” section, you can enter the desired name for your instance. For example, you could use “MyFirstEC2Instance” or “WebAppServer”. Choose a name that best describes the function of the instance for easy identification later. Step 3: Then, select the Amazon Machine Image (AMI) as ‘LINUX’ since we are installing Ansible on a Linux system. Step 4: Select the instance type that suits your requirements. If you have an existing key pair, choose it from the dropdown. If you don’t have one, click on “Create new key pair” and follow the prompts to generate a new key pair for secure access to your instance. Step 5 : Name the key pair something memorable and relevant to your project. Once you’ve entered the name, click on “Create key pair” to generate it. Make sure to download the private key file and store it securely, as you’ll need it to access your instance later. Step 6 : Make sure to select the option to allow HTTP traffic. This is important if you plan to access your application over the web. You can typically do this by checking the box labeled “HTTP” in the inbound rules section of your security group settings. Step 7 : click on launch instance  Step 8: The instance is now being created. You can monitor the progress in the management console. Once the status changes to “running”.  Step 9 : Now Instance is created select the instance you want to connect.  Step 10 : select the instance and click on connect  Step 11 : click on connect  Step 12 : Linux Instance is created. give the sudo su command to switch user . $sudo su Step 13 : to install the ansible package in Linux  $yum install ansible -y Ansible is installed on Linux ec2  For Information Click here  For  more information Visit Cloud Institution 

Scroll to Top