大网数据广告活动
服务器运维问答

Saltstack for firewalld

· 52CE 我爱测

I am trying to get a state set up so that I can add the associated ports open in firewalld. Tried every example I can find and all fail. Here is my current: firewalld: service.running: - enable: True default_zone: - public servic…

问题原文

原帖链接 · Jonathan Hansen · CC BY-SA 3.0

I am trying to get a state set up so that I can add the associated ports open in firewalld.

Tried every example I can find and all fail.

Here is my current:

firewalld:
  service.running:
    - enable: True
  default_zone:
    - public
  services:
    snmpd:
      - short:
        - snmp
      - ports:
        - udp:
          - 161
        - tcp:
          - 161
    ssh:
      - short:
        - ssh
      - ports:
        - tcp:
          - 22
  zones:
    public:
      - short:
        - Public
      - services:
        - ssh
        - snmpd

And this leads to an error on the minion of:

State 'firewalld' in SLS 'firewalld.firewalld' is not formed as a list

I've run this through three different YAML validators and all say it's clean so I'm confused.

已采纳解答

原帖链接 · pepoluan · CC BY-SA 3.0

I assume you are using the firewalld-formula from the official repository?

Please be informed that a "SaltStack Formula" is a "ready-to-use state that you configure using pillars". So, your YAML declaration must NOT be a state declaration, but instead a pillar declaration.

Let me illustrate:

I'll assume you have your state files in /srv/salt and your pillar files in /srv/pillar.

To use the firewalld-formula, you need to create a "pillar" file. Use the provided pillar.example file and save it as /srv/pillar/firewalld/<target-host>.sls, and refer to it from /srv/pillar/top.sls. For example:

# /srv/pillar/top.sls
base:
  # ... other references we skip ...
  'target-host':
    - firewalld.<target-host>

Note: By naming the pillar file <target-host>.sls, we can easily make different pillars for different hosts.

Then, we 'activate' the formula by referencing the firewalld-formula from /srv/salt/top.sls (or other state files under /srv/salt/ using the include: directive).

I'll assume that you cloned the firewalld-formula repo in this way:

cd /srv/salt
git clone https://github.com/saltstack-formulas/firewalld-formula.git
ln -s firewalld-formula/firewalld firewalld

Note: The symlink allows us to refer to the state as firewalld instead of firewalld-formula.firewalld.

Now, edit the /srv/salt/top.sls file to invoke the firewalld state:

# /srv/salt/top.sls
base:
  # ... other references ...
  'target-host':
    - firewalld

Aaand, you're done.

Alternatively, you may use a common state instead and let the Jinja renderer and the Pillar system take care of the 'targeting' details. Let's say your top.sls file has the following:

# /srv/salt/top.sls
base:
  '*':
    # ...other states...
    - hardening
    # ...more states...

Edit the hardening state file as such:

# /srv/salt/hardening/init.sls

# ...various states we skip

include:
  # ... possible other includes ...
{% if pillar.get('firewalld', false) -%}
  # The following will be included *only* if pillar for the minion has the 'firewalld' key defined
  - firewalld
{% endif -%}

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2016-07-21)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。