找不到 Ansible Firewalld 模块

Ansible Firewalld Module Not Found

环境信息:

CentOS Stream release 8
Python 3.8.12
ansible [core 2.12.2]
  config file = /ansible/ansible-myprojects-rhel8/ansible.cfg
  configured module search path = ['/home/ansible/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.8/site-packages/ansible
  ansible collection location = /home/ansible/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/bin/ansible
  python version = 3.8.12 (default, Sep 21 2021, 00:10:52) [GCC 8.5.0 20210514 (Red Hat 8.5.0-3)]
  jinja version = 2.10.3
  libyaml = True

我正在尝试在工作节点的防火墙上打开 http 端口。我的剧本如下:

---
- name: enable web server
  hosts: target1
  tasks:
    - name: install stuff
      yum:
        name:
          - httpd
          - firewalld

    - name: create a welcome page
      copy:
        content: "welcome to the webserver \n"
        dest: /var/www/html/index.html

    - name: enable webserver
      service:
        name: httpd
        state: started
        enabled: true

    - name: enable firewall
      service:
        name: firewalld
        state: started
        enabled: true

    - name: open service in firewall
      firewalld:
        service: httpd
        permanent: true
        state: enabled
        immediate: yes

当我执行剧本时,出现错误:

错误!无法解析 module/action 'firewalld'。这通常表示拼写错误、缺少集合或模块路径不正确。

The error appears to be in '/ansible/ansible-myprojects-rhel8/exercise53_4.yaml': line 28, column 7, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:


    - name: open service in firewall
      ^ here

然后我尝试查看来自 ansible 控制器服务器的文档。比发生以下错误:

[WARNING]: module firewalld not found in: /home/ansible/.ansible/plugins/modules:/usr/share/ansible/plugins/modules:/usr/lib/python3.8/site-packages/ansible/modules

我不明白是模块丢失还是什么。它通过了应该安装 firewalld 的安装任务(或者如果它已安装但没有登录则通过。它只是跳到防火墙中的任务打开服务并给出错误)。

详细输出:

ansible-playbook [core 2.12.2]
  config file = /ansible/ansible-myprojects-rhel8/ansible.cfg
  configured module search path = ['/home/ansible/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.8/site-packages/ansible
  ansible collection location = /home/ansible/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/bin/ansible-playbook
  python version = 3.8.12 (default, Sep 21 2021, 00:10:52) [GCC 8.5.0 20210514 (Red Hat 8.5.0-3)]
  jinja version = 2.10.3
  libyaml = True
Using /ansible/ansible-myprojects-rhel8/ansible.cfg as config file
redirecting (type: modules) ansible.builtin.firewalld to ansible.posix.firewalld
ERROR! couldn't resolve module/action 'firewalld'. This often indicates a misspelling, missing collection, or incorrect module path.

The error appears to be in '/ansible/ansible-myprojects-rhel8/exercise53_4.yaml': line 28, column 7, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:


    - name: open service in firewall
      ^ here 

我读到 post 关于包含 firewalld 模块的集合没有安装在我的控制器节点上,而 firewalld 在 ansible.posix 集合中。

所以我运行下面的命令与ansible用户:

ansible-galaxy collection install ansible.posix

之后问题解决了,但我不明白为什么当我第一次安装ansible(使用yum)时,集合没有安装到我的控制器节点。如果有人对此有想法,请分享。

参考:http://www.freekb.net/Article?id=2991