如何使用firewalld模块同时启用多个服务 - Ansible

如何使用firewalld模块同时启用多个服务 - Ansible

如何使用firewalld模块同时启用多个服务?我正在使用这段代码,它在运行 ansible-playbook 后启用一项服务(https)。它工作得很好。但是,我不知道如何在此代码中启用多个服务,而不仅仅是一个服务(https)。

- name: firewalld configuration
  firewalld:
    zone: public
    service: https
    permanent: yes
    state: enabled
  notify: reload firewalld

我尝试了用于安装多个软件包的相同方法(见下文),但没有成功。它回答错误(见下文)

- name: firewalld configuration
  firewalld:
    zone: public
    service:
      name:
        - https
        - http
    permanent: yes
    state: enabled
  notify: reload firewalld

错误:

fatal: [192.168.0.101]: FAILED! => {"changed": false, "msg": "ERROR: Exception caught: org.fedoraproject.FirewallD1.Exception: INVALID_SERVICE: '{'name': ['https', 'http']}' not among existing services Permanent operation, Services are defined by port/tcp relationship and named as they are in /etc/services (on most systems)"}

答案1

防火墙参数service是一个字符串。使用环形迭代服务列表。例如

- name: firewalld configuration
  firewalld:
    zone: public
    service: "{{ item }}"
    permanent: yes
    state: enable
  notify: reload firewalld
  loop:
    - https
    - http

相关内容