Why I cannot prompt for a variable that will be shared by multiple plays (ansible 1.6.5) -
i have distilled playbook has 3 plays. goal collect database password prompt in 1 play , use same password in other 2 plays.
--- - name: database password hosts: - webservers - dbservers vars_prompt: - name: "db_password" prompt: "enter database password databse user root" default: "root" - hosts: dbservers tasks: - command: echo {{db_password | mandatory }} - hosts: webservers tasks: - command: echo {{db_password | mandatory }}
it fails shown below.
enter database password databse user root [root]: play [database password] ****************************************************** gathering facts *************************************************************** ok: [vc-dev-1] play [dbservers] ************************************************************** gathering facts *************************************************************** ok: [vc-dev-1] task: [command echo {{db_password | mandatory}}] *************************** fatal: [vc-dev-1] => 1 or more undefined variables: 'db_password' undefined fatal: hosts have failed -- aborting play recap ******************************************************************** retry, use: --limit @.../playbook2.retry vc-dev-1 : ok=3 changed=0 unreachable=1 failed=0
i have found following workaround using set_fact assign variable entered user variable playbook scope. seems var_prompt variables not facts , other variables, scope restricted in play prompts them not entire playbook. not sure if feature or bug.
--- - name: database password hosts: - webservers - dbservers vars_prompt: - name: "db_password" prompt: "enter database password databse user root" default: "root" tasks: - set_fact: db_root_password: "{{db_password}}" - hosts: dbservers tasks: - command: echo {{db_root_password | mandatory }} - hosts: webservers tasks: - command: echo {{db_root_password | mandatory }}
Comments
Post a Comment