Ansible无法在sbin文件夹上运行shell模块

问题描述 投票:1回答:1

我在特定主机上运行了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文件夹中的所有命令。是什么原因?感谢您的帮助

python-2.7 ansible ansible-2.x
1个回答
0
投票

忘记了/ sbin文件夹中的所有命令。是什么原因

通常原因$PATH变量,其中不包括/sbin位置。最简单的解决方案是对要运行的二进制文件使用完整路径,因此无需尝试调用iptables,您需要ti have /sbin/iptables

© www.soinside.com 2019 - 2024. All rights reserved.