有没有一种方法可以运行shell脚本,提示从Ansible剧本输入值? [英] Is there a way to run shell script which prompts for input values from Ansible playbook?

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

问题描述

我有一本Ansible剧本,它调用了一个现有的shell脚本.Shell脚本在独立触发时会提示用户输入.我也希望从Ansible剧本获得相同的功能(在Ansible剧本的提示下调用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剧本中尝试了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.

您必须复制用户交互.首先,您需要使用提示进行输入,然后输入通过期望将值提供给您的交互式程序.

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剧本输入值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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