DEV Community

rndmh3ro
rndmh3ro

Posted on • Originally published at zufallsheld.de on

TIL that you can pass variables to Ansible’s import_playbook module

Using Ansible’s import_playbook module I was always under the impression that the module accepts no parameters and boldly stated so! However another commentor helpfully pointed out that I was wrong.

Here’s an example. The first playbook (importer_playbook.yml):

- import_playbook: imported-playbook.yml
  vars:
    foo: hunter2

Enter fullscreen mode Exit fullscreen mode

… simply imports a second playbook (imported_playbook.yml):

- hosts: localhost
  tasks:
  - debug:
      var: foo

Enter fullscreen mode Exit fullscreen mode

Running the importer-playbook results in this:

> ansible-playbook importer-playbook.yml
PLAY [localhost] 
********************************************
TASK [debug] 
********************************************
ok: [localhost] => {
    "foo": "hunter2"
}

PLAY RECAP 
********************************************
localhost : ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0

Enter fullscreen mode Exit fullscreen mode

It’s even stated in the documentation as an example. However I did not scroll this far down. :(

Top comments (0)