Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/security/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我们是否有Ansible命令来运行用户交互shell脚本而不使用playbook?_Ansible_Ansible Ad Hoc - Fatal编程技术网

我们是否有Ansible命令来运行用户交互shell脚本而不使用playbook?

我们是否有Ansible命令来运行用户交互shell脚本而不使用playbook?,ansible,ansible-ad-hoc,Ansible,Ansible Ad Hoc,我有以下需要用户输入的shell脚本: read -e -p "Enter any string:" varible echo 'Entered value is ::' $varible > abc.txt ansible all -a 'sh /home/ansible/test.sh' 我想运行这个脚本,它需要用户在多个服务器中输入,并使用以下yml实现: - name: Here we start hosts: all tasks: # is a list

我有以下需要用户输入的shell脚本:

 read -e -p "Enter any string:" varible
 echo  'Entered value is ::' $varible > abc.txt
 ansible all -a 'sh /home/ansible/test.sh'
我想运行这个脚本,它需要用户在多个服务器中输入,并使用以下yml实现:

- name: Here we start
  hosts: all

  tasks:  # is a list
  - name: Execute the user interactive script
  expect:                                                                   
       command: /usr/bin/sh /home/ansible/test.sh
       responses:
            "Enter any string:": "Success Script Executed"
但如果我尝试使用下面的命令,则相同,因为该命令不适用于用户输入:

 read -e -p "Enter any string:" varible
 echo  'Entered value is ::' $varible > abc.txt
 ansible all -a 'sh /home/ansible/test.sh'
1) 请共享正确的ansible命令,该命令要求用户输入上述脚本


2) 此外,对于我上面的脚本,请代表用户共享使用默认值的正确ansible命令。

您可以使用
ansible
命令运行任何单个ansible模块:

  • 将模块名称作为值提供给
    --module name=module_name
    -m

  • 将模块参数作为值提供给
    --args=module_args
    -a

对于上述任务:

ansible all -m expect -a "command='/usr/bin/sh /home/ansible/test.sh' responses='{\"Enter any string:\": \"Success Script Executed\"}'"

谢谢,你能告诉我,在你提供的答案中,我怎么能提到两个“回答”吗?另外,请回答我的第一个问题,以防万一,如果您知道i.e 1)ansible命令要求用户输入我上面的脚本