So I have a playbook that has a task where it executes a command on the remote host. The output of the remote command is registered to a variable. Is it possible to write this variable to a vars file and use it in other playbooks?
Asked
Active
Viewed 346 times
0
-
msy be with `lineinfile` module? it takes two arguments: 1. dest which is location of your file and 2.line (the value of your variable). look it up – JBone Apr 08 '21 at 17:03
-
@JBone [Doc link](https://docs.ansible.com/ansible/latest/collections/ansible/builtin/lineinfile_module.html) According to the official docs, this module is used to ensure a particular line is in a file, or replace an existing line. Not sure if this is the best module to use. – Abhishek Aditya Apr 09 '21 at 14:57
-
Create a role with delegate to who populate value of var, build a dir https://stackoverflow.com/questions/35605603/using-ansible-set-fact-to-create-a-dictionary-from-register-results, and after import role on another playbook, you can also, use copy module with local option for write json and import as vars files in another playbook. – Derioss Apr 09 '21 at 15:42
-
Entire files can be managed with [template](https://docs.ansible.com/ansible/2.9/modules/template_module.html). A file generated with variables so can be used as a `vars_files` for other playbooks. – seshadri_c Apr 09 '21 at 16:51