Latest Updates

Create An Ansible playbook Which Dynamically Loads Variable File Named the Same As Os_Name And Configure The Os

Task Objective :

Let’s Get Started

[WebServer]192.168.0.109 ansible_connection=ssh ansible_user=venkatesh  ansible_ssh_pass=root192.168.0.113 ansible_connection=ssh ansible_user=root  ansible_ssh_pass=root
[defaults]inventory = data.txthost_key_checking = Falsedeprecation_warnings = falseroles_path = roles:/usr/share/ansible/roles
[privilege_escalation]
become = yesbecome_method = sudobecome_user = rootbecome_ask_pass= true
ansible all -m ping
ansible "node name" -m setup
Ubuntu.ymlpackage: apache2web_port: 80RedHat.ymlpackage: httpdweb_port: 80
- hosts: allvars_files:    - "{{ansible_facts['distribution']}}.yml"tasks:      - name: install apache webserver        package:            name: "{{ package }}"            state: latest      - name: Start Web server service        service:            name: "{{ package }}"            state: started
vars_files:- "{{ansible_facts['distribution']}}.yml"// we have taken os name as variable filename and as we already created os specific files so it will dynamically include only that file ultimatly ansible will get os specific package names
ansible-playbook FileName.yml

No comments