在Ansible中,可以使用command
模块来执行本地的交互式shell脚本。下面是一个包含代码示例的解决方法:
- name: Run interactive shell script locally
hosts: localhost
gather_facts: false
tasks:
- name: Execute shell script locally
command: "/path/to/interactive_script.sh"
args:
chdir: /path/to/script_directory
creates: /path/to/output_file.txt
register: script_output
- name: Display script output
debug:
var: script_output.stdout_lines
上述示例中,我们使用command
模块执行了一个名为/path/to/interactive_script.sh
的交互式shell脚本。chdir
参数指定了脚本的工作目录,creates
参数指定了脚本执行后创建的文件。脚本的输出将保存在script_output
变量中。
最后,我们使用debug
模块显示脚本的输出,通过script_output.stdout_lines
访问脚本输出的内容。
请确保将localhost
添加到Ansible的主机清单中,并将/path/to/interactive_script.sh
替换为实际的脚本路径。