如何在ansible中传递提示?

如何在ansible中传递提示?

我试图在执行以下命令时在 ansible 中传递提示 y 。当我在服务器上手动执行操作时,它会要求提示。我应该如何使用 shell 模块使用 ansible 来做到这一点。请帮助在 ansible 中传递提示

ubuntu@ip-xx-xxx-xx-xx:~$ tsm pending-changes apply
This operation will perform a server restart. Are you sure you wish to continue?
(y/n): 

我的 Ansible 脚本:

- name: Apply pending configuration changes
  shell: source /etc/profile.d/tableau_server.sh && tsm pending-changes apply -u ubuntu -p '{{ tableau_server_admin_password }}' |
    expect "This operation will perform a server restart. Are you sure you wish to continue?\(y\/n\)"
    send "y\n"
  args:
    executable: /bin/bash
  when: inventory_hostname == "xx.xxx.xx.xx"

答案1

这就是ansible期望模块用于:

- name: Apply pending configuration changes
  expect:
    command: /bin/bash -c "source /etc/profile.d/tableau_server.sh && tsm pending-changes apply -u ubuntu -p '{{ tableau_server_admin_password }}'"
    responses:
      '(y/n):': y
  when: inventory_hostname == "xx.xxx.xx.xx"

(无法测试,但类似的事情应该是这样的)

相关内容