Automation Meets Cinema

Automation Meets Cinema

Christopher Nolan's new movie Oppenheimer has been released and is getting praise from all over the world. We are all familiar with his famous works such as Inception, Interstellar, and Dark Knight. I am going to talk about one of his finest works to date, i.e. The Prestige but while integrating his idea with one of my projects. The main plot of the project revolves around 2 magicians who have their take on magic, but, every magic trick consists of three parts, or acts. The first part is called :

The Pledge

The magician shows you something ordinary: a deck of cards, a bird, or a man. He shows you this object. Perhaps he asks you to inspect it to see if it is indeed real, unaltered, and normal. But of course... it probably isn't.

Created 3-4 EC2 t2.micro instances using the Amazon Machine Image as Ubuntu, designated one of them as the host/master server and the others are termed as nodes. The host server will eventually roll out the updates and changes to the nodes using Ansible which is an Infrastructure as a Code tool. After the instances are up and running, the following commands are used to install Ansible :

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

Note: The following commands may differ according to the AMI used to create the instance(s)

The following command is used to export the key-pair login file to the host server :

 scp -i <key-pair.pem> key-pair.pem ubuntu@ec2-43-207-209-136.ap-northeast-1.compute.amazonaws.com:/home/ubuntu/.ssh

We need to include the host servers' IP Addresses and the key that was imported earlier in the hosts file using the following command :

 sudo nano /etc/ansible/hosts

After doing the following tasks the file should be like this

2023-04-16 (3)

And give the hosts file read access using :

 chmod 600 <key-pair.pem>

The Turn

The magician takes the ordinary something and makes it do something extraordinary. Now you're looking for the secret... but you won't find it, because of course you're not really looking. You don't really want to know. You want to be fooled.

So, the stage is set for the act but we should perform a final check, just to be sure. Using the following command :

 ansible servers -m ping

All the servers should return a "pong" to your request.

Now, before creating the playbooks, we can perform some actions using the module (-m) and the (-a) tag such as :

 ansible servers -a "sudo apt update"

Accordingly, this command rolls all the available updates in all the node servers. You can try using other modules from the given link :

https://docs.ansible.com/ansible/2.9/modules/list_of_all_modules.html

An Ansible playbook is a file containing a series of tasks and configurations to be executed on remote hosts. Here is an example of a basic Ansible playbook:

---
- name: My playbook
 hosts: my_hosts
 become: true
 vars:
   my_var: "my_value"
 tasks:
   - name: Install packages
     apt:
       name:
         - package1
         - package2
       state: present

   - name: Create directory
     file:
       path: /my/directory
       state: directory
       owner: root
       group: root
       mode: '0755'

   - name: Copy file
     copy:
       src: /path/to/local/file
       dest: /path/to/remote/file
       owner: root
       group: root
       mode: '0644'

Inventories are created namely development and production to group the remote servers accordingly and also to deploy certain actions according to the need.

The Prestige

But you wouldn't clap yet. Because making something disappear isn't enough; you have to bring it back. That's why every magic trick has a third act, the hardest part, the part we call THE PRESTIGE.

Now, the final part i.e. rolling out the actions to the required servers.

ansible-playbook <playbook_name>.yaml

You can now check the required server instances to check if the playbooks are working properly.

My Project Link: https://github.com/Rajdeep1311/Ansible_Project.git