【问题标题】:ansible command: module returning erroransible 命令:模块返回错误
【发布时间】:2014-08-01 05:04:39
【问题描述】:

尝试使用 ansible 进行 iptables-save

name: Save Netfilter Rules

action: command  iptables-save > /etc/sysconfig/iptables

但这会产生错误

failed: [10.110.211.17] => {"changed": true, "cmd": ["iptables-save", ">", "/etc/sysconfig/iptables"], "delta": "0:00:00.009345", "end": "2014-06-09 16:55:18.306375", "rc": 1, "start": "2014-06-09 16:55:18.297030"}

stderr: Unknown arguments found on commandline

但是通过 ssh 可以正常工作:

ssh root@host "iptables-save > /etc/sysconfig/iptables" 

工作正常,但不能通过 Ansible 命令:模块

我怎样才能做到这一点

【问题讨论】:

    标签: rhel ansible


    【解决方案1】:

    您应该使用shell 模块进行重定向,即

    ...
    name: Save Netfilter Rules
    shell:  iptables-save > /etc/sysconfig/iptables
    

    请看这里ansible docs:

    【讨论】:

      猜你喜欢
      • 2023-03-30
      • 2021-06-16
      • 2015-05-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-09-05
      • 2020-03-29
      • 1970-01-01
      相关资源
      最近更新 更多