Skip to content
This repository has been archived by the owner on Aug 13, 2024. It is now read-only.

Commit

Permalink
use with_dict instead of accessing keys from dict.keys() (#150) (#153)
Browse files Browse the repository at this point in the history
  • Loading branch information
tyxieblub authored and jdauphant committed Jan 20, 2017
1 parent 4c35cc2 commit 6a9ada3
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 18 deletions.
30 changes: 16 additions & 14 deletions tasks/configuration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,49 +2,51 @@
- name: Copy the nginx configuration file
template:
src: nginx.conf.j2
dest: "{{nginx_conf_dir}}/nginx.conf"
dest: "{{ nginx_conf_dir }}/nginx.conf"
notify:
- restart nginx

- name: Ensure auth_basic files created
template:
src: auth_basic.j2
dest: "{{nginx_conf_dir}}/auth_basic/{{ item }}"
dest: "{{ nginx_conf_dir }}/auth_basic/{{ item.key }}"
owner: root
group: "{{nginx_group}}"
group: "{{ nginx_group }}"
mode: 0750
with_items: "{{ nginx_auth_basic_files.keys() }}"
with_dict: "{{ nginx_auth_basic_files }}"

- name: Create the configurations for sites
template:
src: "{{ nginx_sites[item].template | default('site.conf.j2') }}"
dest: "{{nginx_conf_dir}}/sites-available/{{ item }}.conf"
with_items: "{{ nginx_sites.keys() | difference(nginx_remove_sites) }}"
src: "{{ item.value.template | default('site.conf.j2') }}"
dest: "{{ nginx_conf_dir }}/sites-available/{{ item.key }}.conf"
with_dict: "{{ nginx_sites }}"
when: item.key not in nginx_remove_sites
notify:
- reload nginx

- name: Create links for sites-enabled
file:
state: link
src: "{{nginx_conf_dir}}/sites-available/{{ item }}.conf"
dest: "{{nginx_conf_dir}}/sites-enabled/{{ item }}.conf"
with_items: "{{ nginx_sites.keys() | difference(nginx_remove_sites) }}"
src: "{{ nginx_conf_dir }}/sites-available/{{ item.key }}.conf"
dest: "{{ nginx_conf_dir }}/sites-enabled/{{ item.key }}.conf"
with_dict: "{{ nginx_sites }}"
when: item.key not in nginx_remove_sites
notify:
- reload nginx

- name: Create the configurations for independent config file
template:
src: config.conf.j2
dest: "{{nginx_conf_dir}}/conf.d/{{ item }}.conf"
with_items: "{{ nginx_configs.keys() }}"
dest: "{{ nginx_conf_dir }}/conf.d/{{ item.key }}.conf"
with_dict: "{{ nginx_configs }}"
notify:
- reload nginx

- name: Create the configurations for independent config file for streams
template:
src: config_stream.conf.j2
dest: "{{nginx_conf_dir}}/conf.d/stream/{{ item }}.conf"
with_items: "{{ nginx_stream_configs.keys() }}"
dest: "{{ nginx_conf_dir }}/conf.d/stream/{{ item.key }}.conf"
with_dict: "{{ nginx_stream_configs }}"
notify:
- reload nginx
when: nginx_official_repo_mainline
2 changes: 1 addition & 1 deletion templates/auth_basic.j2
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#{{ ansible_managed }}

{% for v in nginx_auth_basic_files[item] %}
{% for v in item.value %}
{{ v }}
{% endfor %}
2 changes: 1 addition & 1 deletion templates/config.conf.j2
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#{{ ansible_managed }}

{% for v in nginx_configs[item] %}
{% for v in item.value %}
{% if v.find('\n') != -1 %}
{{v}}
{% else %}
Expand Down
2 changes: 1 addition & 1 deletion templates/config_stream.conf.j2
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#{{ ansible_managed }}

{% for v in nginx_stream_configs[item] %}
{% for v in item.value %}
{% if v.find('\n') != -1 %}
{{v}}
{% else %}
Expand Down
3 changes: 2 additions & 1 deletion templates/site.conf.j2
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#{{ ansible_managed }}

server {
{% for v in nginx_sites[item] %}
{% for v in item.value %}
{% if v.find('\n') != -1 %}
{{v.replace("\n","\n ")}}
{% else %}
Expand Down

0 comments on commit 6a9ada3

Please sign in to comment.