Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to see prompt text #149

Open
its-johnt opened this issue May 3, 2024 · 4 comments
Open

Unable to see prompt text #149

its-johnt opened this issue May 3, 2024 · 4 comments

Comments

@its-johnt
Copy link

Hi, thanks for your very helpful library. I'm running into an issue where pause tasks with a prompt won't show the prompt text on stdout unless the user knows there's an invisible prompt, enters something, then hits enter. For instance, the examples/ansibleplaybook-simple-with-prompt example from the repo on my Ubuntu 24.04 system shows:

[johnt@work ~/go-ansible/examples/ansibleplaybook-simple-with-prompt (master =)]$ git rev-parse --short HEAD
73bbde1
[johnt@work ~/go-ansible/examples/ansibleplaybook-simple-with-prompt (master =)]$ ls
ansibleplaybook-simple-with-prompt.go  docker  docker-compose.yaml  input.yml  Makefile
[johnt@work ~/go-ansible/examples/ansibleplaybook-simple-with-prompt (master =)]$ go version
go version go1.22.0 linux/amd64
[johnt@work ~/go-ansible/examples/ansibleplaybook-simple-with-prompt (master =)]$ go run .

PLAY [Test playbook for user input] ********************************************

TASK [Gathering Facts] *********************************************************
ok: [127.0.0.1]

TASK [simple prompt 1] *********************************************************

It stops there, but if you know it's a prompt you can enter the text and hit enter.

If there's any other info I can provide to help, please let me know.

@apenella
Copy link
Owner

Hi @its-johnt
Thanks for opening that issue. Let me check it and I will get you back.

@apenella apenella added question Further information is requested and removed Pending Analysis labels Jun 7, 2024
@apenella
Copy link
Owner

apenella commented Jun 7, 2024

Hi @its-johnt !
I apologize for the delayed response.

Regarding the issue with the prompt message not showing up, I haven't come to a conclusion yet. However, I've noticed that using vars_prompt instead of the pause task, as shown in the following example, does display the prompt:

- name: Test playbook for user input
  hosts: localhost
  gather_facts: false

  vars_prompt:
    - name: input_this
      prompt: Type in anything
      private: true
    - name: input_that
      prompt: Type in another thing
      private: true
  tasks:

    - name: echo user input this
      debug:
        msg: "You typed this: '{{ input_this }}'"
 
    - name: echo user input that
      debug:
        msg: "You typed that: '{{ input_that }}'"

When executed, the prompt message appears as expected.

❯ go run ansibleplaybook-simple-with-prompt.go
Type in anything:
Type in another thing:

PLAY [Test playbook for user input] ********************************************

TASK [echo user input this] ****************************************************
ok: [127.0.0.1] =>
  msg: 'You typed this: ''asdf'''

TASK [echo user input that] ****************************************************
ok: [127.0.0.1] =>
  msg: 'You typed that: ''asdf'''

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

Additionally, setting the private variable in vars_prompt to false has the same behaviour as using the pause task, the prompt message isn't displayed.

Do you think this helps you move forward with fixing the issue?

Thank you!

@apenella apenella added solution proposed and removed question Further information is requested labels Jun 7, 2024
@its-johnt
Copy link
Author

Hi, thanks for taking a look. Unfortunately vars_prompt won't help us. Mostly we want to print a message when a task fails, then allow the person running the playbook to fix things in the background then hit enter to try running the task again. For now I've split up the prompt into multiple tasks - one debug to show the message we were trying to show in the pause task, followed by a pause task. It's not perfect, but it's certainly an improvement.

@apenella
Copy link
Owner

Hi @its-johnt!
I need to delve into the Ansible code to understand how it handles the prompt and why it's hidden when running the playbook via go-ansible. From what I've seen, it's not a redirection to stderr or similar.
I'll keep you updated if I discover anything that could improve this behaviour.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants