From 20d4b6829ab05e18c13c95dd7b456fcd1d921389 Mon Sep 17 00:00:00 2001 From: Emilien Mantel Date: Fri, 26 Apr 2019 09:52:07 +0200 Subject: [PATCH] [WIP] Lint --- meta/main.yml | 1 - tasks/install_Debian.yml | 13 +++---------- tasks/prepare.yml | 8 +++++++- tasks/site.yml | 2 +- tasks/ssl/acme.yml | 19 +++++++++++++++---- tasks/ssl/standard.yml | 9 +++++++-- tests/test.yml | 20 +++++++++++++++----- 7 files changed, 48 insertions(+), 24 deletions(-) diff --git a/meta/main.yml b/meta/main.yml index 23d04cb..6df101c 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -26,4 +26,3 @@ galaxy_info: - nginx - cdn dependencies: [] - diff --git a/tasks/install_Debian.yml b/tasks/install_Debian.yml index d52fe53..96bb246 100644 --- a/tasks/install_Debian.yml +++ b/tasks/install_Debian.yml @@ -11,17 +11,9 @@ cache_valid_time: 3600 changed_when: false -- name: APT | Force OpenSSL from backports (fix dependency break) - apt: - pkg: openssl - state: latest - default_release: "{{ ansible_distribution_release + '-backports' }}" - when: nginx_backports - - name: APT | Install nginx and dependencies apt: pkg: "{{ nginx_apt_package }}" - state: present default_release: "{{ ansible_distribution_release + '-backports' if nginx_backports else ansible_distribution_release }}" - name: APT | Install nginx modules @@ -50,9 +42,10 @@ repo: 'https://github.com/Neilpang/acme.sh.git' dest: '{{ nginx_acmesh_git_dir }}' update: no + version: master - - name: SHELL | Install acme.sh - shell: ./acme.sh --install --home "{{ nginx_acmesh_dir }}" + - name: COMMAND | Install acme.sh + command: ./acme.sh --install --home "{{ nginx_acmesh_dir }}" args: chdir: "{{ nginx_acmesh_git_dir }}" creates: "{{ nginx_acmesh_dir }}" diff --git a/tasks/prepare.yml b/tasks/prepare.yml index 010e566..d191905 100644 --- a/tasks/prepare.yml +++ b/tasks/prepare.yml @@ -9,7 +9,13 @@ check_mode: no - name: SHELL | Get module list - shell: nginx -V 2>&1 | tr -- - '\n' | grep -A 1 with | grep _module | sed -r 's/_module//g; s/\s+//g' | sort + shell: | + nginx -V 2>&1 | + tr -- - '\n' | + grep -A 1 with | + grep _module | + sed -r 's/_module//g; s/\s+//g' | + sort args: executable: /bin/sh register: shell_modules diff --git a/tasks/site.yml b/tasks/site.yml index 9529ce3..eb7d4d0 100644 --- a/tasks/site.yml +++ b/tasks/site.yml @@ -75,7 +75,7 @@ - name: FILE | Disable sites file: - path: "{{ nginx_etc_dir}}/sites-enabled/{{ item | nginx_site_filename }}" + path: "{{ nginx_etc_dir }}/sites-enabled/{{ item | nginx_site_filename }}" state: absent loop: "{{ nginx_sites }}" notify: ['reload nginx', 'restart nginx freebsd'] diff --git a/tasks/ssl/acme.yml b/tasks/ssl/acme.yml index 9605d94..a57b896 100644 --- a/tasks/ssl/acme.yml +++ b/tasks/ssl/acme.yml @@ -46,8 +46,13 @@ warn: false when: fake_site.changed and ansible_virtualization_type == 'docker' - - name: SHELL | Get certificates - shell: '{{ nginx_acmesh_bin }} --home {{ nginx_acmesh_dir }} --issue{% if item.name is string %} -d {{ item.name }}{% else %}{% for name in item.name %} -d {{ name }}{% endfor %}{% endif %} --nginx {% if nginx_acmesh_test %}--test{% endif %}' + - name: COMMAND | Get certificates + command: | + {{ nginx_acmesh_bin }} + --home {{ nginx_acmesh_dir }} + --issue{% if item.name is string %} -d {{ item.name }}{% else %}{% for name in item.name %} -d {{ name }}{% endfor %}{% endif %} + --nginx + {% if nginx_acmesh_test %}--test{% endif %} args: creates: "{{ nginx_acmesh_dir }}/{{ item | nginx_site_name }}/{{ item | nginx_site_name }}.key" loop: "{{ acme_create }}" @@ -60,8 +65,14 @@ path: "{{ nginx_ssl_dir }}/{{ item | nginx_site_name }}" loop: "{{ acme_create }}" - - name: SHELL | Install certificates - shell: '{{ nginx_acmesh_bin }} --home {{ nginx_acmesh_dir }} --install-cert -d {{ item | nginx_site_name }} --fullchain-file {{ nginx_ssl_dir }}/{{ item | nginx_site_name }}/{{ item | nginx_site_name }}.crt --key-file {{ nginx_ssl_dir }}/{{ item | nginx_site_name }}/{{ item | nginx_site_name }}.key --reloadcmd "service nginx restart"' + - name: COMMAND | Install certificates + command: | + {{ nginx_acmesh_bin }} + --home {{ nginx_acmesh_dir }} + --install-cert -d {{ item | nginx_site_name }} + --fullchain-file {{ nginx_ssl_dir }}/{{ item | nginx_site_name }}/{{ item | nginx_site_name }}.crt + --key-file {{ nginx_ssl_dir }}/{{ item | nginx_site_name }}/{{ item | nginx_site_name }}.key + --reloadcmd "service nginx restart" args: creates: "{{ nginx_ssl_dir }}/{{ item | nginx_site_name }}/{{ item | nginx_site_name }}.key" loop: "{{ nginx_ssl_pairs }}" diff --git a/tasks/ssl/standard.yml b/tasks/ssl/standard.yml index af797c0..5c65d6d 100644 --- a/tasks/ssl/standard.yml +++ b/tasks/ssl/standard.yml @@ -57,10 +57,15 @@ no_log: not nginx_debug_role - name: COMMAND | Create self-signed certificates - command: "openssl req -new -newkey rsa:2048 -sha256 -days 3650 -nodes -x509 -subj '/CN={{ item | nginx_site_name }}' -keyout {{ item | nginx_site_name + '.key' }} -out {{ item | nginx_site_name + '.crt' }}" + command: | + openssl req + -new -newkey rsa:2048 -sha256 -days 3650 -nodes -x509 + -subj '/CN={{ item | nginx_site_name }}' + -keyout {{ item | nginx_site_name + '.key' }} + -out {{ item | nginx_site_name + '.crt' }} args: chdir: "{{ nginx_ssl_dir + '/' + item | nginx_site_name }}" - creates: "{% if item.force is defined and item.force %}/tmp/dummy{% else %}{{ nginx_ssl_dir + '/' + item | nginx_site_name + '/' + item | nginx_site_name + '.crt' }}{% endif %}" + creates: "{{ '/tmp/dummy' if item.force is defined and item.force else nginx_ssl_dir + '/' + item | nginx_site_name + '/' + item | nginx_site_name + '.crt' }}" loop: "{{ nginx_ssl_pairs }}" when: item.self_signed is defined notify: restart nginx diff --git a/tests/test.yml b/tests/test.yml index 48688ff..bc18c50 100644 --- a/tests/test.yml +++ b/tests/test.yml @@ -23,10 +23,20 @@ src: "file/test.key" dest: "{{ int_ansible_ssl_dir }}/test.key" - - name: LINEINFILE | Add all hosts in /etc/hosts - lineinfile: - line: "127.0.0.1\tlocalhost {% for s in nginx_sites %}{% if s.name is string %}{{ s.name }}{% else %}{% for n in s.name %}{{ n }} {% endfor %}{% endif %} {% if s.redirect_from is defined %}{% for rf in s.redirect_from %}{{ rf }} {% endfor %}{% endif %}{% endfor %}" - regexp: '^127\.0\.0\.1' + - name: COPY | Add all hosts in /etc/hosts + copy: + content: | + 127.0.0.1 localhost + {% for s in nginx_sites %} + {% if s.name is string %} + 127.0.0.1 {{ s.name }} + {% else %} + 127.0.0.1 {% for n in s.name %}{{ n }} {% endfor %} + {% endif %} + {% if s.redirect_from is defined %} + 127.0.0.1 {% for rf in s.redirect_from %}{{ rf }} {% endfor %} + {% endif %} + {% endfor %} dest: "/etc/hosts" unsafe_writes: yes @@ -355,7 +365,7 @@ # -------------------------------- - name: -- VERIFY PHP SITES -- uri: - url: "http://{{ item.name}}/" + url: "http://{{ item.name }}/" return_content: yes register: p loop: "{{ nginx_sites }}"