Skip to content

Commit

Permalink
Fix Ansible Lint
Browse files Browse the repository at this point in the history
  • Loading branch information
HanXHX committed Sep 1, 2021
1 parent a2780d3 commit 8c6c4dc
Show file tree
Hide file tree
Showing 13 changed files with 113 additions and 111 deletions.
2 changes: 2 additions & 0 deletions .ansible-lint
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
enable_list:
- fqcn-builtins
16 changes: 8 additions & 8 deletions handlers/main.yml
Original file line number Diff line number Diff line change
@@ -1,46 +1,46 @@
---

- name: reload nginx
command: nginx -t
ansible.builtin.command: nginx -t
notify:
- real-reload nginx
- docker reload nginx

- name: restart nginx
command: nginx -t
ansible.builtin.command: nginx -t
notify:
- real-restart nginx
- docker restart nginx

- name: real-reload nginx
service:
ansible.builtin.service:
name: nginx
state: reloaded
when: ansible_virtualization_type != 'docker'

- name: real-restart nginx
service:
ansible.builtin.service:
name: nginx
state: restarted
when: ansible_virtualization_type != 'docker'

- name: docker reload nginx
command: service nginx reload
ansible.builtin.command: service nginx reload
args:
warn: false
when: ansible_virtualization_type == 'docker'

- name: docker restart nginx
command: service nginx restart
ansible.builtin.command: service nginx restart
args:
warn: false
when: ansible_virtualization_type == 'docker'

- name: restart nginx freebsd
service:
ansible.builtin.service:
name: nginx
state: restarted
when: ansible_distribution == "FreeBSD"

- name: setup
action: setup
ansible.builtin.setup:
10 changes: 5 additions & 5 deletions tasks/config.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---

- name: TEMPLATE | Deploy nginx.conf
template:
ansible.builtin.template:
src: "etc/nginx/nginx.conf.j2"
dest: "{{ nginx_etc_dir }}/nginx.conf"
mode: 0644
Expand All @@ -10,7 +10,7 @@
notify: reload nginx

- name: TEMPLATE | Deploy all helpers
template:
ansible.builtin.template:
src: "{{ item }}"
dest: "{{ nginx_helper_dir }}/{{ item | basename | regex_replace('.j2$','') }}"
mode: 0644
Expand All @@ -20,7 +20,7 @@
notify: reload nginx

- name: TEMPLATE | Deploy custom http configuration
template:
ansible.builtin.template:
src: "etc/nginx/conf.d/custom.conf.j2"
dest: "{{ nginx_etc_dir }}/conf.d/custom.conf"
mode: 0644
Expand All @@ -29,7 +29,7 @@
notify: reload nginx

- name: LINEINFILE | Fix path
lineinfile:
ansible.builtin.lineinfile:
regexp: '{{ item.0.regexp }}'
line: '{{ item.0.line }}'
dest: '{{ item.1 }}'
Expand All @@ -45,7 +45,7 @@
when: nginx_fastcgi_fix_realpath

- name: COPY | Add modules manually
copy:
ansible.builtin.copy:
content: |
{% for m in nginx_load_modules %}
load_module {{ m }};
Expand Down
4 changes: 2 additions & 2 deletions tasks/htpasswd.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
---

- name: FILE | Delete htpasswd file
file:
ansible.builtin.file:
path: "{{ nginx_htpasswd_dir }}/{{ item.name }}"
state: absent
loop: "{{ nginx_htpasswd }}"
when: item.state is defined and item.state == 'absent'
no_log: "{{ not nginx_debug_role }}"

- name: HTPASSWD | Manage files
htpasswd:
ansible.builtin.htpasswd:
name: "{{ item.1.name }}"
password: "{{ item.1.password }}"
path: "{{ nginx_htpasswd_dir }}/{{ item.0.name }}"
Expand Down
18 changes: 9 additions & 9 deletions tasks/install_Debian.yml
Original file line number Diff line number Diff line change
@@ -1,51 +1,51 @@
---

- name: SET_FACT | Bypass https://github.com/ansible/ansible/issues/19874
set_fact:
ansible.builtin.set_fact:
ansible_distribution_release: 'buster'
when: ansible_facts.distribution_major_version == "buster/sid"

- name: APT | Update cache
apt:
ansible.builtin.apt:
update_cache: true
cache_valid_time: 3600
changed_when: false

- name: APT | Install nginx and dependencies
apt:
ansible.builtin.apt:
pkg: "{{ nginx_apt_package }}"
default_release: "{{ ansible_distribution_release + '-backports' if nginx_backports else ansible_distribution_release }}"

- name: APT | Install nginx modules
apt:
ansible.builtin.apt:
pkg: "{{ nginx_module_packages }}"
state: present

- name: APT | Install python-passlib
apt:
ansible.builtin.apt:
pkg: "python{% if ansible_python_version is version('3', '>=') %}3{% endif %}-passlib"
state: present

- name: STAT | Check acme.sh is installed
stat:
ansible.builtin.stat:
path: "{{ nginx_acmesh_dir }}"
register: acme

- block:

- name: APT | Install git
apt:
ansible.builtin.apt:
pkg: git

- name: GIT | Get acme.sh
git:
ansible.builtin.git:
repo: 'https://github.com/Neilpang/acme.sh.git'
dest: '{{ nginx_acmesh_git_dir }}'
update: false
version: master

- name: COMMAND | Install acme.sh
command: ./acme.sh --install --home "{{ nginx_acmesh_dir }}"
ansible.builtin.command: ./acme.sh --install --home "{{ nginx_acmesh_dir }}"
args:
chdir: "{{ nginx_acmesh_git_dir }}"
creates: "{{ nginx_acmesh_dir }}"
Expand Down
12 changes: 6 additions & 6 deletions tasks/install_FreeBSD.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,28 @@
- block:

- name: COMMAND | Create /usr/local/etc/fdfs/http.conf
command: touch /usr/local/etc/fdfs/http.conf
ansible.builtin.command: touch /usr/local/etc/fdfs/http.conf
args:
creates: /usr/local/etc/fdfs/http.conf
register: fd1

- name: LINEINFILE | Tune fdfs
lineinfile:
ansible.builtin.lineinansible.builtin.file:
regexp: ^load_fdfs_parameters_from_tracker
line: load_fdfs_parameters_from_tracker=false
path: /usr/local/etc/fdfs/mod_fastdfs.conf
register: fd2

- name: SERVICE | Restart nginx when fdfs is tuned
service:
ansible.builtin.service:
name: nginx
state: restarted
when: fd1.changed or fd2.changed

when: true

- name: FILE | Create configuration dir (like Debian)
file:
ansible.builtin.file:
path: "{{ nginx_etc_dir }}/{{ item }}"
state: directory
mode: 0755
Expand All @@ -49,14 +49,14 @@
- sites-enabled

- name: FILE | Create log directory
file:
ansible.builtin.file:
path: "{{ nginx_log_dir }}"
owner: "{{ nginx_user }}"
group: wheel
mode: 0755
state: directory

- name: SERVICE | Enable nginx
service:
ansible.builtin.service:
name: nginx
enabled: true
16 changes: 8 additions & 8 deletions tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
---

- name: INCLUDE_VARS | Related to OS
include_vars: "{{ ansible_distribution }}.yml"
ansible.builtin.include_vars: "{{ ansible_distribution }}.yml"
tags: ['nginx::site', 'nginx::ssl']

- name: INCLUDE_TASKS | Install
include_tasks: "install_{{ ansible_distribution }}.yml"
ansible.builtin.include_tasks: "install_{{ ansible_distribution }}.yml"
tags: ['nginx::site', 'nginx::ssl']

- name: IMPORT_TASKS| Prepare
import_tasks: prepare.yml
ansible.builtin.import_tasks: prepare.yml
tags: ['nginx::site', 'nginx::ssl']

- name: IMPORT_TASKS| Install
import_tasks: config.yml
ansible.builtin.import_tasks: config.yml

- name: IMPORT_TASKS| Upstream configuration
import_tasks: upstream.yml
ansible.builtin.import_tasks: upstream.yml

- name: IMPORT_TASKS| htpasswd configuration
import_tasks: htpasswd.yml
ansible.builtin.import_tasks: htpasswd.yml

- name: IMPORT_TASKS| SSL configuration
import_tasks: ssl/main.yml
ansible.builtin.import_tasks: ssl/main.yml
tags: ['nginx::ssl']

- name: IMPORT_TASKS| Sites configuration
import_tasks: site.yml
ansible.builtin.import_tasks: site.yml
tags: ['nginx::site']
10 changes: 5 additions & 5 deletions tasks/prepare.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---

- name: SHELL | Get Nginx version
shell: nginx -v 2>&1 | sed -r 's#.*/##;' | cut -d ' ' -f 1
ansible.builtin.shell: nginx -v 2>&1 | sed -r 's#.*/##;' | cut -d ' ' -f 1
args:
executable: /bin/sh
register: nginx_version
Expand All @@ -11,7 +11,7 @@
- skip_ansible_lint

- name: SHELL | Get module list
shell: |
ansible.builtin.shell: |
nginx -V 2>&1 |
tr -- - '\n' |
grep -A 1 with |
Expand All @@ -27,19 +27,19 @@
- skip_ansible_lint

- name: SET_FACT | Save modules
set_fact:
ansible.builtin.set_fact:
nginx_modules: "{{ shell_modules.stdout_lines }}"

- name: FILE | Create folders
file:
ansible.builtin.file:
dest: "{{ item.dir }}"
owner: "{{ item.owner }}"
mode: "{{ item.mode }}"
state: directory
loop: "{{ nginx_dirs }}"

- name: FILE | Create ansible facts dir
file:
ansible.builtin.file:
path: /etc/ansible/facts.d
state: directory
mode: 0755
Expand Down
Loading

0 comments on commit 8c6c4dc

Please sign in to comment.