Playbook | Prompt to confirm before to do some action

Hi,

I like to ask a confirmation at prompt before some action.
But the plabook skipped all the tasks.

Here is the plabook:


  • name: domain management
    hosts: foo
    gather_facts: true

    vars:
    domain_join_credentials:
    domain_join_user: !vault |
    xxxxx
    domain_join_password: !vault |
    xxxxx

    vars_prompt:

    • name: “domain_join_user”
      prompt: “Give the AD user that will be used to bond the domain”
      default: “{{ domain_join_credentials.domain_join_user }}”
      private: false

    • name: “domain_join_password”
      prompt: “Give the password”
      default: “{{ domain_join_credentials.domain_join_password }}”
      private: true

    • name: “action_leave_domain”
      prompt: “Do you really want to leave the domain ? (YES to confirm)”
      private: no
      default: “NO”

    • name: “action_join_domain”
      prompt: “Do you want to join the domain ? (YES to confirm)”
      private: no
      default: “NO”

    tasks:

    • group_by: key={{ ansible_distribution }}
      changed_when: false

    • name: Confirmation to quit the domain
      ansible.builtin.debug:
      msg: “You chose to leave the domain.”
      when: action_leave_domain in [“YES”]

    • name: Run leave_ad role
      ansible.builtin.include_role:
      name: leave_ad
      when: action_leave_domain in [“YES”]

    • name: Confirmation to join the domain
      ansible.builtin.debug:
      msg: “You chose to join the domain.”
      when: action_join_domain in [“YES”]

    • name: Run join_ad role
      ansible.builtin.include_role:
      name: join_ad
      when: action_join_domain in [“YES”]

Here is the output:>

ok: [machine]

TASK [Group hosts by distribution] ************************************************************************************
ok: [machine]

TASK [Confirmation to quit the domain] ********************************************************************************
skipping: [machine]

TASK [Run leave_ad role] **********************************************************************************************
skipping: [machine]

TASK [Confirmation to join the domain] ********************************************************************************
skipping: [machine]

TASK [Run join_ad role] ***********************************************************************************************
skipping: [machine]

PLAY RECAP ************************************************************************************************************
machine : ok=2 changed=0 unreachable=0 failed=0 skipped=4 rescued=0 ignored=0

Thanks for in advance.

In your case, the tasks are being skipped, probably because "YES" is not an exact match to the input, use a debug action to confirm the content.

Just FYI, the prompts themselves are skipped in 2 cases:

  • no tty, ansible assumes it is in batch mode
  • The variable requested has already been provided at higher precedence, like via an extra var.

There are no extra variable.
When running the playbook on a console, it does not ask the confirmation, it just run and skipped the tasks.
I expected a pause and the question into the console, but nothing.

I remove the ‘vars’ and ‘user’ and ‘password’ in var_prompt to see the behavior but it is not better.

i should have been more explicit, i used extra vars as an example, but you are setting the domain_join_credentials and domain_join_user already in vars: , those will never prompt, i’m guessing something similar is going on with the action_leave_domain

Yes, i am aware about that declaration.
To try to debug, i disabled the ‘vars’ and ‘var_prompt’ of these declarations.

But i expected a different behaviour with join and leave domain action.
But there is no prompt.