New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

firewalld module can not set target property of a zone #49232

Open
juame opened this Issue Nov 28, 2018 · 6 comments

Comments

Projects
None yet
5 participants
@juame

juame commented Nov 28, 2018

SUMMARY

It's possible to set a target property with firewall-cmd for a specific firewalld zone:

~]# firewall-cmd --zone=zone-name --set-target=<default|ACCEPT|REJECT|DROP>

(Source: RHEL 7 Documentation)

To accept any traffic in a zone it would be great to be able to change from target: default to target: ACCEPT with the firewalld module. Or vice versa.

ISSUE TYPE
  • Feature Idea
COMPONENT NAME

firewalld

ADDITIONAL INFORMATION

With firewall-cmd:

# firewall-cmd --zone=myzone --list-all
myzone (active)
  target: default
  icmp-block-inversion: no
  interfaces: eth1
  sources: 
  services: 
  ports: 
  protocols: 
  masquerade: no
  forward-ports: 
  source-ports: 
  icmp-blocks: 
  rich rules: 
# firewall-cmd --zone=myzone --set-target=ACCEPT --permanent
success

# firewall-cmd --reload
success

# firewall-cmd --zone=myzone --list-all
myzone (active)
  target: ACCEPT
  icmp-block-inversion: no
  interfaces: eth1
  sources: 
  services: 
  ports: 
  protocols: 
  masquerade: no
  forward-ports: 
  source-ports: 
  icmp-blocks: 
  rich rules: 

My workaround with command...:

- name: populate variable for zone target
  command: 'firewall-cmd --permanent --zone={{ nic.key }} --get-target'
  changed_when: false
  when: nic.value.firewalld_zone_state == 'present'
  become: yes
  register: firewalld_zones_targets
  loop: "{{ lookup('dict', baseos_nics, wantlist=True) }}"
  loop_control:
    loop_var: nic
  tags:
    - firewalld

- name: ensure firewalld zone target
  command: 'firewall-cmd --permanent --zone={{ zone.nic.key }} --set-target={{ zone.nic.value.firewalld_zone_target }}'
  when:
    - zone.stdout is defined
    - zone.stdout != zone.nic.value.firewalld_zone_target|default('default')
  become: yes
  notify: reload firewalld
  loop: '{{ firewalld_zones_targets.results|default([]) }}'
  loop_control:
    loop_var: zone
  tags:
    - firewalld

Vars:

baseos_nics:
  myzone:
    interface: eth0
    firewalld_zone_state: present
    firewalld_zone_target: default
    ipv4_address: '{{ ansible_eth0.ipv4.address }}'
@ansibot

This comment has been minimized.

Contributor

ansibot commented Nov 28, 2018

Hi @juame, thank you for submitting this issue!

click here for bot help

@ansibot

This comment has been minimized.

Contributor

ansibot commented Nov 28, 2018

@sivel

This comment has been minimized.

Member

sivel commented Dec 4, 2018

!component =lib/ansible/modules/system/firewalld.py

@gundalow

This comment has been minimized.

Contributor

gundalow commented Dec 4, 2018

!component lib/ansible/galaxy/data/apb/vars/main.yml.j2
!component lib/ansible/modules/commands/command.py
!component lib/ansible/modules/system/interfaces_file.py
!component lib/ansible/modules/utilities/logic/include_vars.py
!component lib/ansible/parsing/utils/yaml.py
!component lib/ansible/playbook/loop_control.py
!component lib/ansible/plugins/lookup
!component test/integration/targets/include_vars/vars/environments/development/services/webapp.yml
!component test/integration/targets/shadowed_module/library/tags

@gundalow gundalow removed the support:core label Dec 4, 2018

@ansibot

This comment has been minimized.

Contributor

ansibot commented Dec 4, 2018

Files identified in the description:

If these files are inaccurate, please update the component name section of the description or use the !component bot command.

click here for bot help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment