Thanks. It works for localhost. But let's say i need to save information from a task on all remote hosts in a local file (or files), how do i do it? So that in the next yml file, i can load the local file for all remote hosts.
On Wednesday, August 28, 2019 at 10:31:46 PM UTC-7, Vladimir Botka wrote: > > On Wed, 28 Aug 2019 22:00:20 -0700 (PDT) > pk s <[email protected] <javascript:>> 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/bb07d9a2-6830-4caa-83a6-f80794fd4333%40googlegroups.com.
