If we have data in .csv format
[ansible@ip-172-31-80-19 ~]$ vi inventory.txt
[ansible@ip-172-31-80-19 ~]$ cat inventory.txt
webserver1 ansible_host=172.31.85.190
sqlserver1 ansible_host=172.31.85.192
[ansible@ip-172-31-80-19 ~]$ vi credentials.csv
[ansible@ip-172-31-80-19 ~]$ cat credentials.csv
Hostname,Password
webserver1,password
sqlserver1,password
[ansible@ip-172-31-80-19 ~]$ vi lookups.yml
[ansible@ip-172-31-80-19 ~]$ cat lookups.yml
-
name: Test Connectivity
hosts: webserver1
vars:
ansible_ssh_pass: "{{ lookup('csvfile', 'webserver1 file=credentials.csv delimiter=,') }}"
tasks:
- name: create a dummy file on webserver
command: touch /tmp/csv_lookups.txt
[ansible@ip-172-31-80-19 ~]$
---------------------------------------------------------------------------------------------------------
If we have data in .ini format
[ansible@ip-172-31-80-19 ~]$ vi credentials.ini
[ansible@ip-172-31-80-19 ~]$ cat credentials.ini
[webserver1]
password=password
[sqlserver1]
password=password
[ansible@ip-172-31-80-19 ~]$
[ansible@ip-172-31-80-19 ~]$ vi lookups.yml
[ansible@ip-172-31-80-19 ~]$ cat lookups.yml
-
name: Test Connectivity
hosts: webserver1
vars:
ansible_ssh_pass: "{{ lookup('ini', 'password section=webserver1 file=credentials.ini') }}"
tasks:
- name: create a dummy file on webserver
command: touch /tmp/ini_lookups.txt
[ansible@ip-172-31-80-19 ~]$
No comments:
Post a Comment