Joh*_*Lab 6 linux centos ansible firewalld
如何使用 firewalld 模块一次启用多个服务?我正在使用此代码在运行 ansible-playbook 后启用一项服务 (https)。它工作得很好。但是,我无法弄清楚如何在此代码中启用多个服务,而不仅仅是一个 (https)。
- name: firewalld configuration
firewalld:
zone: public
service: https
permanent: yes
state: enabled
notify: reload firewalld
Run Code Online (Sandbox Code Playgroud)
我尝试了用于安装多个软件包但没有运气的相同方法(见下文)。它回答错误(见下文)
- name: firewalld configuration
firewalld:
zone: public
service:
name:
- https
- http
permanent: yes
state: enabled
notify: reload firewalld
Run Code Online (Sandbox Code Playgroud)
错误:
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)"}
Run Code Online (Sandbox Code Playgroud)
firewalld参数service是一个字符串。使用循环来迭代服务列表。例如
- name: firewalld configuration
firewalld:
zone: public
service: "{{ item }}"
permanent: yes
state: enable
notify: reload firewalld
loop:
- https
- http
Run Code Online (Sandbox Code Playgroud)