有没有办法运行 shell 脚本来提示 Ansible playbook 中的输入值? [英] Is there a way to run shell script which prompts for input values from Ansible playbook?

查看:32
本文介绍了有没有办法运行 shell 脚本来提示 Ansible playbook 中的输入值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 Ansible 剧本,它调用现有的 shell 脚本.独立触发时的 Shell 脚本,提示一些用户输入.我也希望 Ansible playbook 具有相同的功能(根据 Ansible playbook 的提示调用 shell 脚本).

I have an Ansible playbook which calls an existing shell script. Shell script when triggered standalone, prompts for some user input. I want the same functionality from Ansible playbook as well (call shell script with prompting from Ansible playbook).

我在 Ansible playbook 中尝试了 shell/command/raw 选项(没有运气).

I tried with shell/command/raw options in Ansible playbook (with no luck).

 - hosts: localhost
   gather_facts: false

   become: true
   become_user: oracle
   become_flags: 'content-ansible'

   pre_tasks:
    - include_vars: vars.yml
   tasks:
    - name: Do Create Users....
      shell: cd "{{v_dir}}" && yes | sh script.sh

推荐答案

Ansible 不允许您访问交互式命令.

Ansible does not give you access to interactive commands.

您必须复制用户交互.首先,您必须使用 Prompts 请求输入,然后您有使用 expect 将值提供给您的交互式程序.

You have to duplication the user interaction. First you have to ask for the input with Prompts and second you have to feed the values to your interactive program with expect.

但这不是 Ansible 的生活方式,因为它是不可复制的.使用 Ansible 的主要原因是创建幂等作业,每次都做同样的事情.如果您要求用户输入,则作业取决于输入,这意味着每次调用它时它可能会做不同的事情.

But this is not the Ansible way of life, because it is not reproducible. The main reason to use Ansible is to create idempotent jobs, which do everytime the same thing. If you ask for user input, the job depends an the input and this means it may do different things each time it is called.

这篇关于有没有办法运行 shell 脚本来提示 Ansible playbook 中的输入值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆