官术网_书友最值得收藏!

Ensuring that FirewallD is present and enabled

As you can imagine, the first step is to ensure that FirewallD is installed:

- name: Ensure FirewallD is installed 
  yum: 
    name: firewalld 
    state: present 
  become: True

Since we want to be sure that we will not lose our SSH connection when we enable FirewallD, we will ensure that SSH traffic can always pass through it:

- name: Ensure SSH can pass the firewall 
  firewalld: 
    service: ssh 
    state: enabled 
    permanent: True 
    immediate: True 
  become: True

To do so, we have used the firewalld module. This module will take parameters that are very similar to the ones the firewall-cmd console would use. You will have to specify the service that is to be authorized to pass the firewall, whether you want this rule to apply immediately or not, and whether or not you want the rule to be permanent, so that after a reboot the rule will still be present.

You can specify the service name (such as ssh) using the service parameter, or you can specify the port (such as 22/tcp) using the port parameter.

Now that we have installed FirewallD and we are sure that our SSH connection will survive, we can enable it as we do any other service:

- name: Ensure FirewallD is running 
  service: 
    name: firewalld 
    state: started 
    enabled: True 
  become: True 
主站蜘蛛池模板: 蕉岭县| 当雄县| 奈曼旗| 眉山市| 炉霍县| 宜州市| 天长市| 疏勒县| 晋宁县| 开远市| 孟津县| 普洱| 茶陵县| 台中县| 电白县| 多伦县| 平远县| 民丰县| 芮城县| 五指山市| 二连浩特市| 高尔夫| 嵊泗县| 新兴县| 普格县| 房山区| 高碑店市| 肥城市| 屏山县| 华亭县| 根河市| 磴口县| 沙河市| 鸡西市| 扬州市| 邵阳市| 阳谷县| 阜南县| 霸州市| 洮南市| 武山县|