How do I share ansible variables across hosts using vars_prompt -
in ansible, code on remote machine, , want use result vars_prompt
again on different host. i've searched around, , docs make sound should use {{ hostvars.local_server_name_in_vagrant_group.local_username }}
, using example below set context. however, says index dictionary doesn't exist when referencing hostvars
. instead, shown below, vars_prompt
twice. gross! tips?
btw, there's discussion on whether or not using vars_prompt great idea. have confirmed usage, indeed, want use vars_prompt. thanks!
- hosts: vagrant vars_prompt: local_username: "enter desired local username" ... remote task activity using local_username... - hosts: localhost connection: local vars_prompt: local_username: "enter desired local username, again (please) ... host task activity, using local_username ...
as said in comment question :
you can use set_facts register variable fact of current host , access different one. not think standard variables stored after role/tasks.
here example :
- name: first connection: local hosts: host1 tasks: - name: register real root user localhost facts set_fact: fact_for_host1="1" - name: second connection: local hosts: host2 tasks: - debug: msg="{{ hostvars['host1']['fact_for_host1'] }}"
note connection: local
present local tests purpose.
Comments
Post a Comment