Firewalldモジュールを使用して複数のサービスを同時に有効にする方法 - Ansible

Firewalldモジュールを使用して複数のサービスを同時に有効にする方法 - Ansible

ファイアウォールモジュールを使用して同時に複数のサービスを有効にする方法は? ansible-playbookを実行した後、サービス(https)を有効にするこのコードを使用しています。それは非常にうまく動作します。ただし、このコードでは、1つのサービス(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

おすすめ記事