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

118 views
Skip to first unread message

Neha Singh

unread,
Oct 11, 2022, 2:02:52 AM10/11/22
to Ansible Project
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

Dick Visser

unread,
Oct 11, 2022, 4:02:34 AM10/11/22
to ansible...@googlegroups.com
you could supply (or use an existing) environment variable to signal
that a CI is being used
> --
> You received this message because you are subscribed to the Google Groups "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/693827dc-4a7d-4bba-9adb-b768ccce24fdn%40googlegroups.com.

Brian Coca

unread,
Oct 11, 2022, 8:59:07 AM10/11/22
to ansible...@googlegroups.com
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?)

--
----------
Brian Coca

Neha Singh

unread,
Oct 11, 2022, 11:55:47 PM10/11/22
to Ansible Project
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
Reply all
Reply to author
Forward
0 new messages