-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from dseira/master
Added new ng states
- Loading branch information
Showing
8 changed files
with
365 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
# -*- coding: utf-8 -*- | ||
# vim: ft=sls | ||
|
||
{% from "fail2ban/ng/map.jinja" import fail2ban with context %} | ||
fail2ban.ng.config.fail2ban: | ||
{% if fail2ban.config is defined %} | ||
{% if fail2ban.config.source_path is defined %} | ||
{% set fail2ban_config = fail2ban.config.source_path %} | ||
{% else %} | ||
{% set fail2ban_config = 'salt://fail2ban/ng/files/config.jinja' %} | ||
{% endif %} | ||
file.managed: | ||
- name: {{ fail2ban.prefix }}/etc/fail2ban/fail2ban.local | ||
- source: {{ fail2ban_config }} | ||
- user: {{ fail2ban.user|default('root') }} | ||
- group: {{ fail2ban.group|default('root') }} | ||
- mode: '{{ fail2ban.mode|default("644")}}' | ||
- template: jinja | ||
{% if fail2ban.config.source_path is not defined %} | ||
- context: | ||
config: | ||
Definition: {{ fail2ban.config|yaml }} | ||
{% endif %} | ||
{% else %} | ||
file.absent: | ||
- name: {{ fail2ban.prefix }}/etc/fail2ban/fail2ban.local | ||
{% endif %} | ||
- watch_in: | ||
- service: {{ fail2ban.service }} | ||
fail2ban.ng.config.jails: | ||
{% if fail2ban.jails is defined %} | ||
{% if fail2ban.jails.source_path is defined %} | ||
{% set fail2ban_jails = fail2ban.jails.source_path %} | ||
{% else %} | ||
{% set fail2ban_jails = 'salt://fail2ban/ng/files/config.jinja' %} | ||
{% endif %} | ||
file.managed: | ||
- name: {{ fail2ban.prefix }}/etc/fail2ban/jail.local | ||
- source: {{ fail2ban_jails }} | ||
- user: {{ fail2ban.user|default('root') }} | ||
- group: {{ fail2ban.group|default('root') }} | ||
- mode: '{{ fail2ban.mode|default("644")}}' | ||
- template: jinja | ||
{% if fail2ban.jails.source_path is not defined %} | ||
- context: | ||
config: {{ fail2ban.jails|yaml }} | ||
{% endif %} | ||
{% else %} | ||
file.absent: | ||
{% endif %} | ||
- watch_in: | ||
- service: {{ fail2ban.service }} | ||
{% for name, options in fail2ban.actions|dictsort %} | ||
{% if options.config.source_path is defined %} | ||
{% set fail2ban_actions = options.config.source_path %} | ||
{% else %} | ||
{% set fail2ban_actions = 'salt://fail2ban/ng/files/config.jinja' %} | ||
{% endif %} | ||
fail2ban.ng.config.action.{{ name }}: | ||
{% if ( 'enabled' in options and options.enabled ) or ('enabled' not in options ) %} | ||
file.managed: | ||
- name: {{ fail2ban.prefix }}/etc/fail2ban/action.d/{{ name }}.local | ||
- source: {{ fail2ban_actions }} | ||
- user: {{ fail2ban.user|default('root') }} | ||
- group: {{ fail2ban.group|default('root') }} | ||
- mode: '{{ fail2ban.mode|default("644")}}' | ||
- template: jinja | ||
- watch_in: | ||
- service: {{ fail2ban.service }} | ||
{% if options.config.source_path is not defined %} | ||
- context: | ||
config: {{ options.config|yaml }} | ||
{% endif %} | ||
{% elif 'enabled' in options and not options.enabled %} | ||
file.absent: | ||
- name: {{ fail2ban.prefix }}/etc/fail2ban/action.d/{{ name }}.local | ||
{% endif %} | ||
{% endfor %} | ||
{% for name, options in fail2ban.filters|dictsort %} | ||
{% if options.config.source_path is defined %} | ||
{% set fail2ban_filters = options.config.source_path %} | ||
{% else %} | ||
{% set fail2ban_filters = 'salt://fail2ban/ng/files/config.jinja' %} | ||
{% endif %} | ||
fail2ban.ng.config.filter.{{ name }}: | ||
{% if ( 'enabled' in options and options.enabled ) or ('enabled' not in options ) %} | ||
file.managed: | ||
- name: {{ fail2ban.prefix }}/etc/fail2ban/filter.d/{{ name }}.local | ||
- source: {{ fail2ban_filters }} | ||
- user: {{ fail2ban.user|default('root') }} | ||
- group: {{ fail2ban.group|default('root') }} | ||
- mode: '{{ fail2ban.mode|default("644")}}' | ||
- template: jinja | ||
- watch_in: | ||
- service: {{ fail2ban.service }} | ||
{% if options.config.source_path is not defined %} | ||
- context: | ||
config: {{ options.config|yaml }} | ||
{% endif %} | ||
{% elif 'enabled' in options and not options.enabled %} | ||
file.absent: | ||
- name: {{ fail2ban.prefix }}/etc/fail2ban/filter.d/{{ name }}.local | ||
{% endif %} | ||
{% endfor %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# | ||
# This file is managed by salt. Do not edit by hand. | ||
# | ||
{% macro print_config(name, value) %} | ||
{%- set name_length = name|length %} | ||
{%- if value is string %} | ||
{{ name }} = {{ value }} | ||
{%- elif value is number %} | ||
{{ name }} = {{ value }} | ||
{%- else %} | ||
{#- Since strings are also sequences, there's no way to explicitly test for lists #} | ||
{{ name }} = {{ value|first }} | ||
{%- if value|length > 1 %} | ||
{%- for item in value[1:] %} | ||
{{ item|indent(width=name_length + 3, indentfirst=True) }} | ||
{%- endfor %} | ||
{%- endif %} | ||
{%- endif %} | ||
{%- endmacro %} | ||
|
||
{%- for section, section_data in config|dictsort %} | ||
[{{section}}] | ||
{%- for name, value in section_data|dictsort %} | ||
{{- print_config(name, value) }} | ||
{%- endfor %} | ||
{% endfor %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# -*- coding: utf-8 -*- | ||
# vim: ft=sls | ||
|
||
include: | ||
- fail2ban.ng.install | ||
- fail2ban.ng.config | ||
- fail2ban.ng.service |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# -*- coding: utf-8 -*- | ||
# vim: ft=sls | ||
|
||
{% from "fail2ban/ng/map.jinja" import fail2ban with context %} | ||
fail2ban.ng.install: | ||
pkg.installed: | ||
- name: {{ fail2ban.package }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# -*- coding: utf-8 -*- | ||
# vim: ft=jinja | ||
|
||
{% set os_family_map = salt['grains.filter_by']({ | ||
'FreeBSD': { | ||
'package': 'py27-fail2ban', | ||
'service': 'fail2ban', | ||
'prefix': '/usr/local', | ||
}, | ||
'Gentoo': { | ||
'package': 'net-analyzer/fail2ban', | ||
'service': 'fail2ban', | ||
'prefix': '', | ||
}, | ||
'default': { | ||
'package': 'fail2ban', | ||
'service': 'fail2ban', | ||
'prefix': '', | ||
'user': 'root', | ||
'group': 'root', | ||
'mode': '644', | ||
}, | ||
}, merge=salt['pillar.get']('fail2ban:lookup')) %} | ||
|
||
{% set fail2ban = salt['pillar.get']( | ||
'fail2ban:ng', | ||
default=os_family_map, | ||
merge=True | ||
) | ||
%} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# -*- coding: utf-8 -*- | ||
# vim: ft=sls | ||
|
||
{% from "fail2ban/ng/map.jinja" import fail2ban with context %} | ||
fail2ban.ng.service: | ||
{% if ( 'enabled' in fail2ban and fail2ban.enabled ) or ('enabled' not in fail2ban ) %} | ||
service.running: | ||
- name: {{ fail2ban.service }} | ||
- enable: True | ||
- require: | ||
- pkg: {{ fail2ban.package }} | ||
{% elif 'enabled' in fail2ban and not fail2ban.enabled %} | ||
service.dead: | ||
- name: {{ fail2ban.service }} | ||
- enable: False | ||
{% endif %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters