1. Dynamic variable
We will create a variable file name same as os name and will use the variable name to configure
out target node.
How we can do it is by using defining a variable name with the os_name
1. I do have one control domain and 2 managed (Target) nodes.
a. Have one control node (AWS [ Free Tier] or Virtual Box)
b. Have one or 2 Managed nodes (AWS or Virtual Box [ Centos/amazon linux and ubuntu/debian)
Note: Keep your key safe.
2. Config file
# cat /etc/ansible/ansible.cfg
[defaults]
inventory=/root/myhosts
host_key_checking=false
[proviledge_escalation]
become=true
3. Inventory file
[web1]
192.168.10.10 ansible_user=ec2-user ansible_ssh_private_key_file=/home/ec2-user/pkey.pem ansible_connection=ssh
192.168.10.12 ansible_user=root ansible_ssh_pass=changeme ansible_connection=ssh
[web2]
192.168.10.20 ansible_user=ec2-user ansible_ssh_private_key_file=/home/ec2-user/pkey.pem ansible_connection=ssh
192.168.10.12 ansible_user=root ansible_ssh_pass=changeme ansible_connection=ssh
[root@master wk16]# cat RedHat.yaml
package_name: httpd
[root@master wk16]# cat Denian.yaml
package_name: apache2
[root@master wk16]# cat myplaybook.yaml
- hosts: all
vars_files:
- " {{ ansible_facts['os_family'] }}.yaml"
tasks:
- package:
name: "{{ package_name }}"
state: present
- service:
name: "{{ package_name }}"
state: started
[root@master wk16]# ansible-playbook myplaybook.yaml
Run the playbook
# ap myplaybook.yaml
4. Open your browser and open the page
192.168.10.10
you should be able to see default page.
Monday, December 21, 2020
Ansible - Variable Load ...
Subscribe to:
Post Comments (Atom)
Git branch show detached HEAD
Git branch show detached HEAD 1. List your branch $ git branch * (HEAD detached at f219e03) 00 2. Run re-set hard $ git reset --hard 3. ...
-
snmpconfig command allow you to managge snmpv1/v3 agent configuration on SAN switch. Event trap level is mapped with event severity level....
-
Firmware upgrade on HPE SuperDom Flex 280 - prerequisites tasks a. Set up repo b. Upload firmware to your webserver 1. For foundation so...
-
Disabling the Telnet protocol on Brocade SAN switches By default, telnet is enabled on Brocade SAN switches. As part of security hardening o...
No comments:
Post a Comment