Invalid vars_prompt for roles

I have a set of Ansible playbooks and the main yml file is similar to this

 - hosts: all roles: - common - install_nginx 

I want to add a confirmation message when the playbook starts. I tried this and did not work.

 - hosts: all vars_prompt: - name: CONFIRM prompt: Just to confirm you will install stuff tasks: - fail: no deployment this time when: CONFIRM != 'yes' roles: - common - install_nginx 

How can I use vars_prompt in this case without changing each role ?

+5
source share
2 answers

If you look at the result of starting your play with vars_prompt , you will see that the fail task starts after other roles. This is also mentioned in Ansible docs for slot machines and roles :

If the game still has a "tasks" section, these tasks are performed after completing the roles.

As stated above, it is also mentioned whether you want to force the task to run before any roles, you can use pre_tasks .

So, to get a hint in the confirmation style, you can simply do this:

 - hosts: all vars_prompt: - name: CONFIRM prompt: Just to confirm you will install stuff pre_tasks: - fail: no deployment this time when: CONFIRM != 'yes' roles: - common - install_nginx 
+3
source

I'm not very sure, but the way this works is:

 - hosts: all vars_prompt: - name: "confirm" prompt: Just to confirm you will install stuff private: no default: "no" tasks: - name: Install Nginx apt: name=nginx sudo: true when: confirm == "yes" 

Now, if we need to call each role based on the condition, I believe that we will use tags .

+1
source

Source: https://habr.com/ru/post/1239390/


All Articles