我在特定主机上运行了Ansible Playbook:
[例如,当我从Ansible执行iptables -L
命令时,出现此错误:
changed: [host] => {"changed": true, "cmd": "iptables -L", "delta": "0:00:00.018402", "end": "2020-04-26 09:33:11.274857", "failed_when_result": false, "msg": "non-zero return code", "rc": 127, "start": "2020-04-26 09:33:11.256455", "stderr": "/bin/sh: iptables: command not found", "stderr_lines": ["/bin/sh: iptables: command not found"], "stdout": "", "stdout_lines": []}
示例示例:
---
- hosts: all
gather_facts: no
tasks:
- name: ls
shell: tuned -v
args:
executable: /usr/sbin
- name: iptables flush filter
iptables:
chain: "{{ item }}"
flush: yes
with_items: [ 'INPUT', 'FORWARD', 'OUTPUT' ]
- name: Get iptables rules | No resilience comment
command: iptables -L
become: yes
args:
executable: /sbin
库存文件:
[hosts]
host
[all:vars]
ansible_user=ansible_user
ansible_become_user=root
ansible_ssh_pass=pass
ansible_become=yes
但是iptables已安装在计算机上。我检查了更多命令,但没有找到/sbin
文件夹中的所有命令。是什么原因?感谢您的帮助
忘记了/ sbin文件夹中的所有命令。是什么原因
通常原因$PATH
变量,其中不包括/sbin
位置。最简单的解决方案是对要运行的二进制文件使用完整路径,因此无需尝试调用iptables
,您需要ti have /sbin/iptables