On Wed, 28 Aug 2019 22:00:20 -0700 (PDT)
pk s <[email protected]> wrote:

> How do i store/use information retrieved from running a playbook task later
> in another playbook task? I tried dumping the information in json format
> from the first playbook/task to a file. But then how do i read/pass this
> information to the new playbook task as input?

Short answer: Use "vars_files" or "include_vars".

Details: It's possible to store the variables in a file. For example the play

        - hosts: localhost
          vars:
            test_var1: VAR-1
            test_var2: VAR-2
            test_var3: VAR-3
          tasks:
            - copy:
                content: |
                  test_var1: {{ test_var1 }}
                  test_var2: {{ test_var2 }}
                  test_var3: {{ test_var3 }}
                dest: amnesiac-01.yml

creates the file with the variables

        $ cat amnesiac-01.yml 
        test_var1: VAR-1
        test_var2: VAR-2
        test_var3: VAR-3

Use "vars_files" or "include_vars" to read the variables. For example the play

        - hosts: localhost
          tasks:
            - include_vars: amnesiac-01.yml
            - debug:
                msg: "{{ msg.split('\n') }}"
              vars:
                msg: |
                  test_var1: {{ test_var1 }}
                  test_var2: {{ test_var2 }}
                  test_var3: {{ test_var3 }}

gives

        ok: [localhost] => {
            "msg": [
                "test_var1: VAR-1", 
                "test_var2: VAR-2", 
                "test_var3: VAR-3", 
                ""
            ]
        }
...

Cheers,

        -vlado

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/20190829073128.242f53ff%40gmail.com.

Attachment: pgpwDs3z1KKy4.pgp
Description: OpenPGP digital signature

Reply via email to