Why I cannot prompt for a variable that will be shared by multiple plays (ansible 1.6.5)

后端 未结 3 818
逝去的感伤
逝去的感伤 2021-02-01 06:05

I have distilled a playbook that has three plays. The goal is to collect the database password from a prompt in one play and then use the same password in the other two plays.

3条回答
  •  忘了有多久
    2021-02-01 06:54

    I have found the following workaround using set_fact to assign the variable entered by a user into a variable with playbook scope. It seems that var_prompt variables are not like facts and other variables, its scope is restricted in the play that prompts for them not the entire playbook. I am not sure if this is a feature or a bug.

    ---
    
    - name: database password
      hosts:
        - webservers
        - dbservers
      vars_prompt:
        - name: "db_password"
          prompt: "Enter Database Password for 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 }}
    

提交回复
热议问题