1
votes

I have a "master" ansible playbook in which I call multiple playbooks using "import_playbook". At this point all the variables which are needed in the "child" playbooks are retrieved from the inventory file and this is working.

#master_playbook.yml
- import_playbook: playbook1.yaml
- import_playbook: playbook2.yaml

What I'd like to do is instead of listing the passwords required in the "child" playbooks in the inventory file, I'd like the "master" playbook to prompt the user for the required passwords and then pass those passwords to the "child" playbooks. The "child" playbooks would still retrieve the remaining variables (non-passwords) needed from the inventory file.

I can get the usage of vars_prompt to work and be able to input the passwords, however the part I'm stuck on is being able to then pass those variables from the "master" playbook to the "child" playbooks as part of the "import_playbook" operation.

Looking to accomplish something equivalent to the below, but this does not work.

#master_playbook.yml
-vars_prompt:
  - name: "password1"
    prompt: "Enter password1"
  - name: "password2"
    prompt: "Enter password2"
- import_playbook: playbook1.yaml
  vars:
    password1: "{{ password1 }}"
    password2: "{{ password2 }}"
- import_playbook: playbook2.yaml
  vars:
    password1: "{{ password1 }}"
    password2: "{{ password2 }}"
1

1 Answers

0
votes

I created the following playbook

---
- hosts: localhost
  roles:
    - parent
  tasks:
- name: Importing child01 playbook
  import_playbook: child01.yml
...

I then ran the following command:

 ansible-playbook -e "pass1=blah" ./import.yml

Both the parent role and child01 playbook just have a debug statement showing the value of pass1. The output I got is as follows:

PLAY [localhost] ***************************************************************

TASK [Gathering Facts] *********************************************************
ok: [localhost]

TASK [parent : Parent task 1] **************************************************
ok: [localhost] => {
    "pass1": "blah"
}

PLAY [localhost] ***************************************************************

TASK [Gathering Facts] *********************************************************
ok: [localhost]

TASK [child01 : Child 1 first task] ********************************************
ok: [localhost] => {
    "pass1": "blah"
}

PLAY RECAP *********************************************************************
localhost                  : ok=4    changed=0    unreachable=0    failed=0

So, cannot include using vars_prompt or vars, but can pass in on the command line. Maybe this can work for you?