Skip to content

Commit

Permalink
fix config tag, append ';' to additional config-lines if needed
Browse files Browse the repository at this point in the history
  • Loading branch information
ansibleguy committed May 5, 2024
1 parent bc1f25a commit b679f56
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
5 changes: 5 additions & 0 deletions filter_plugins/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class FilterModule(object):
def filters(self):
return {
"safe_key": self.safe_key,
"config_line_end": self.config_line_end,
"ensure_list": self.ensure_list,
"prepare_letsencrypt": self.prepare_letsencrypt,
}
Expand All @@ -14,6 +15,10 @@ def filters(self):
def safe_key(key: str) -> str:
return regex_replace(r'[^0-9a-zA-Z\.]+', '', key.replace(' ', '_'))

@staticmethod
def config_line_end(line: str) -> str:
return '' if line.endswith(';') else ';'

@staticmethod
def ensure_list(data: (str, list)) -> list:
# if user supplied a string instead of a list => convert it to match our expectations
Expand Down
12 changes: 9 additions & 3 deletions tasks/debian/add_site.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,19 @@
ansible.builtin.debug:
var: site_item.value
when: debug | bool
tags: [config]

- name: "Nginx | Site '{{ name }}' | Showing debug info - running config"
ansible.builtin.debug:
var: site
when: debug | bool
tags: [config]

- name: "Nginx | Site '{{ name }}' | Processing local certs"
ansible.builtin.import_tasks: add_certs.yml
when: "not site.plain_only | bool and site.ssl.mode in ['selfsigned', 'existing', 'ca']"
when:
- not site.plain_only | bool
- "site.ssl.mode in ['selfsigned', 'existing', 'ca']"
tags: [certs]

# as letsencrypt generator could be skipped on previous run
Expand All @@ -33,7 +37,7 @@
- name: "Nginx | Site '{{ name }}' | Processing basic-auth"
ansible.builtin.import_tasks: add_basic_auth.yml
when: site.basic_auth.enable | bool
tags: [auth]
tags: [config, auth]

- name: "Nginx | Site '{{ name }}' | Adding cache directory"
ansible.builtin.file:
Expand All @@ -43,6 +47,7 @@
owner: "{{ NGINX_CONFIG.user }}"
group: "{{ NGINX_CONFIG.group }}"
when: site.proxy.cache.enable | bool
tags: [config]

- name: "Nginx | Site '{{ name }}' | Config"
ansible.builtin.template:
Expand All @@ -51,11 +56,12 @@
mode: 0640
owner: 'root'
group: "{{ NGINX_CONFIG.group }}"
tags: [auth]
tags: [auth, config]
notify: [Validate-nginx-config, Reload-nginx]

- name: "Nginx | Site '{{ name }}' | Enabling"
ansible.builtin.file:
src: "/etc/nginx/sites-available/site_{{ name }}"
dest: "/etc/nginx/sites-enabled/site_{{ name }}"
state: link
tags: [config]
2 changes: 1 addition & 1 deletion tasks/debian/sites.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,4 @@
tags: [config, sites, certs, auth]
args:
apply:
tags: [config, sites]
tags: [sites]
4 changes: 2 additions & 2 deletions templates/etc/nginx/sites-available/inc/site_https.j2
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ server {
# additional lines
{% endif %}
{% for line in site.config_additions_root | ensure_list %}
{{ line }}
{{ line }}{{ line | config_line_end }}
{% endfor %}

}
Expand All @@ -97,7 +97,7 @@ server {
# additional lines
{% endif %}
{% for line in site.config_additions | ensure_list %}
{{ line }}
{{ line }}{{ line | config_line_end }}
{% endfor %}

}

0 comments on commit b679f56

Please sign in to comment.