Creating an Ansible Playbook which will dynamically load the variable file named same as OS_name and Configuring Web Server.
Mohit Singh Tomar
DevOps Engineer | Python | Flask | Ansible | Docker | Kubernetes | Jenkins | Openshift | Shell Scripting | IOT |
In this Article, I'll show you how to create an Ansible Playbook which will dynamically load the variable file named same as OS_name and Configuring Web Server.
In this task, we have to create a dynamic var files , with name of remote server which we will used in the playbook. For this task I'm using two AWS EC2 instance, one is AMI2 and other is Ubuntu, you can also use your own local system for this task.
Let's Start Implementation :-
Prerequisites :-
- Ansible must be installed in controller node
- Managed nodes login name, password or key and IP must be known to Controller Node's user
1- Launching Instance :-
2- Configuring Host File :-
Here we give the user name according to the distribution used and also need same aws key pair which has been used at the time of launching instance. Give your key name in the .pem format (that key-pair file should be within permission of 600).
3- Configuring ansible.cfg file
[defaults] inventory = /etc/ansible/hosts host_key_checking = False deprecation_warnings = False command_warnings = False [privilege_escalation] become = True become_method = True become_user = root become_ask_pass = False
4- Now Playbook and other required files :-
(A) Creting "Amazon.yml" file -
(B) Creting "Ubuntu.yml" file -
(C) Creating Web Page "var.html" -
(D) Creating Ansible Playbook "setup.yml" -
- hosts: all vars_files: - "{{ ansible_facts['distribution'] }}.yml" tasks: - name: Installing Web Server package: name: "{{ package }}" state: present - name: Copying Web Pages template: src: var.html dest: "{{ doc_root }}" - name: Starting Web Services service: name: "{{ service }}" state: started
5- Running the Playbook :-
Now, Let's check if the Web Services are running or not on both instances.
- For Ubuntu
2. For Amazon
That's all
I hope this article will help you to understand the concept behind it.
Thank you for Reading .....!!!!!!!!!!!