>>> main.yaml

---
- hosts: localhost
  connection: local
  gather_facts: false
  vars_files:
     - child.yml
  tasks:
     - debug:
         var: username

     - name: Run Custom Module
       run_task:
         ip: "{{ ip }}"
         username: "{{ username }}"
         password: "{{ password }}"
       no_log: false
       register: result

>>> child.yaml

---
- name: Child Playbook
  hosts: all
  vars_files:
    - secrets.txt
  vars:
    test_user: "{{ username }}"

Note:

run_task is custom module which accepts three parameters as input. secrets.txt is ansible-vault encrypted file which contains one key-value pair: username, password

Command to run the playbook:

ansible-playbook -vvvv main.yml --vault-password-file  ~/.vault_pass  -e 'ip=10.0.0.0'

I want to include this child yaml file where ever am using these credentials instead of repeating the code in main playbooks.

0

There are 0 best solutions below