我有一组LANCOM WiFi AP。它们支持SSH,但它们有一个自定义接口(没有python)。
当我尝试运行Ansible的command、shell和script模块时,我得到了一个很长的错误。不过,它可以与raw模块一起工作。
我有一个很长的脚本,必须在一个SSH会话中运行。ansible有没有办法通过管道将.txt文件与剧本中包含原始模块的一组路由器连接起来?
发布于 2015-10-03 03:45:46
只需在主机和任务之间添加"gather_facts: False“即可。(来自:https://groups.google.com/forum/#!topic/ansible-project/WP4XM_7PUz0)
发布于 2015-05-21 21:46:35
我的理解是,原始模块基本上只是执行对目标主机的纯ssh调用,在ssh命令行上传递任何参数。因此,无法在ansible中通过管道将文本文件传递给命令。但是,您可以通过将文件读取到ansible变量中,然后将其传递给原始命令来执行非常类似的操作。大致是这样的:
- hosts: waps
vars:
command_string: "{{ lookup('file', '/path/to/commands.txt') }}"
tasks:
raw: "{{ command_string }}"要使文本文件的格式正确,可能需要一些努力,但我看不出有什么理由不能这样做。
编辑:这是我刚刚成功运行的测试。首先,我创建了一个包含以下内容的commands.txt文件:
rm -f /tmp/foo.txt
echo one >> /tmp/foo.txt
echo two >> /tmp/foo.txt
if [ -f /tmp/foo.txt ] ; then
echo three >> /tmp/foo.txt
fi我的行动手册几乎与上面所示的完全相同:
- hosts: testhost
user: test-user
vars:
command_string: "{{ lookup('file', '/tmp/commands.txt') }}"
tasks:
- debug: var=command_string
- raw: "{{ command_string }}"当我运行上面的程序时,它在testhost上创建了包含以下文本的文件/tmp/foo.txt:
one
two
three 发布于 2015-09-11 17:58:14
可能是因为ansible要求python-simplejson可用于执行除raw和script之外的所有模块。所有其他应用程序都需要安装python以及python-simplejson
https://stackoverflow.com/questions/30375301
复制相似问题