0

I see the issue when I try to set multiple services to the zone.
Only first one is set and another always comes with the following error:

TASK [Set services] *******************************************************************************************************************************************************************************************************************************
changed: [localhost] => (item=ssh)
failed: [localhost] (item= samba) => {"ansible_loop_var": "item", "changed": false, "item": " samba", "msg": "ERROR: Exception caught: org.fedoraproject.FirewallD1.Exception: INVALID_SERVICE: Zone 'work': ' samba' not among existing services Permanent operation, Services are defined by port/tcp relationship and named as they are in /etc/services (on most systems)"}


If I swich servises and put samba as a firs one than the same error is generated for ssh

Main playbook:

- name: Configure Firewalld
  hosts: localhost
  gather_facts: no

  vars:
    firewall:
    - zone: work
      service: ssh, samba
    - zone: public
      service: samba

  tasks:
  - name: Set services
    include_tasks: ./service.yml
    loop: "{{firewall | selectattr('service', 'defined') | list}}"
    loop_control:
      loop_var: service

Service playbook:


- set_fact:
    zone: "{{service.zone}}"


- name: "Servcie name"
  debug:
    var: item 
  with_items: "{{service.service | split(',')}}"


- name: Set services 
  ansible.posix.firewalld:
    zone: "{{zone}}"
    service: "{{item}}"
    state: enabled
    permanent: yes
  with_items: "{{service.service | split(',')}}"
  register: result

Any suggestions how to fix that?

1 Answer 1

0

I was able to figured out where was the issue.
In the service playbook you need to replace:
old:

- name: Set services 
  ansible.posix.firewalld:
    zone: "{{zone}}"
    service: "{{item}}"
    state: enabled
    permanent: yes
  with_items: "{{service.service | split(',')}}"
  register: result

new:

- name: Set services 
  ansible.posix.firewalld:
    zone: "{{zone}}"
    service: "{{item}}"
    state: enabled
    permanent: yes
  with_items: "{{service.service | split(',') | map('trim')}}"
  register: result

Empty space was the issue

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .