Override Ansible Prompt Statement (used with pause module in playbook) during automation

Hi Team,

I have written one playbook which is calling prompt statement (through pause module) and based on prompt response, it is calling the role. Please find the written playbook below:

- hosts: primary-metal-console:primary-virtual-console


gather_facts: yes

pre_tasks:

- name: Verification Step before starting the playbook

pause:

prompt: “You are starting staging patching playbook on {{ansible_hostname}} \n To Continue, please enter ‘YES’”

register: result


roles:

- role: patch_stage

when: result.user_input == “YES”

Now, this is working properly while I ran the playbook through CMD. But We have automation (rundeck and soon to be a nightly jenkins patch build) that trigger patch playbooks. This change will break the ability of those playbooks to run. Since the default response is ‘NO’, any time this playbook is triggered in ‘non interactive mode’ it won’t do anything. I’m fine with the prompt being there, but there needs to be some way for automation to run the playbook. It could be some variable that can be specified to skip the check when playbook runs through automation.
Overall, is there any way to skip the prompt or that conditional check to call role, while playbook runs through automation?

Thanks & Regards

Neha Singh

you could supply (or use an existing) environment variable to signal
that a CI is being used

if ansible detects it is running in batch (no tty) it will not prompt,
so I would suggest setting defaults or allowing other methods of
providing the value (extra vars?)

Hi Guys,

Thank you for your suggestion. I need some clarification on the above given points.

Regarding using any environment variable from Command Line to check whether the playbook has been executing from there or through via automation (like rundeck or Jenkins), that’s what your are specifying from your point? Could you please let me know any specific env variable which I can used here. Because I have this restriction in code to use any existing var, don’t want to set up any new ones. That would be helpful if you could share your views.

I wanted to confirm, like setting extra vars in runback or Jenkins before running any playbook. Could you please explain the same in detail. Or other way of setting the var, please let me know.

I just wanted to know any way to skip the prompt or that conditional check to call role, while my playbook runs through automation, any detail guidance from your side will be really helpful. I am looking forward to it.

Thanks & Regards

Neha Singh