How to test if playbook is being run interactively

248 views
Skip to first unread message

Dick Visser

unread,
Jan 21, 2022, 5:09:14 PM1/21/22
to ansible...@googlegroups.com
Hi

Somewhere halfway through one of our playbooks there is a 'pause' task that prompts for input:

- name: Database restoration - timestamp selection
  pause:
    prompt: |
      Select the number of a backup date to restore from:

        {% for ts in backup_timestamps_available %}
        {{ (loop.index|string).ljust(8) ~ '%Y-%m-%d (%A) %H:%M:%S' | strftime(ts) }}
        {% endfor %}
    echo: true
  register: ts_select
  when: db_restore


But in some scenarios this playbook is being run from a shell wrapper, which can be non-interactive, in which case this step will bail with:

[WARNING]: Not waiting for response to prompt as stdin is not interactive



I'd like to gracefully stop right at the beginning when db_restore is set but the play is not run interactively.
I can check in the shell wrapper, but that doens't know about ansible extra vars.

Is there a way to check in the playbook for interactiveness?


thx



--
Dick Visser
Trust & Identity Service Operations Manager
GÉANT

Brian Coca

unread,
Jan 24, 2022, 10:08:04 AM1/24/22
to Ansible Project
No builtin way (yet) but you can setup a 'is_interactive' vars_prompt
with default to 'no', when non interactive it will always be 'no'

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

Reply all
Reply to author
Forward
0 new messages