Skip to content

Commit

Permalink
Batch mode
Browse files Browse the repository at this point in the history
  • Loading branch information
bviktor committed Nov 21, 2023
1 parent 60a5b6d commit d510a2b
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 12 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ This role installs nginx and configures hosts.

| Name | Required | Example | Description |
|---|---|---|---|
| `nginx_batch` | no | `<list>` | Supply the below parameters as a list, see examples. |
| `domain` | yes | `foo.com` | Domain to host. |
| `mode` | yes | `wordpress` | Hosting mode. Possible values are `dirlist`, `php`, `proxy`, `redirect`, `static`, `wordpress`. |
| `path` | no | `/var/www/html/noobient.com` | Document root. Defaults to `/var/www/html/<domain>` for `php`, `static`, and `wordpress`, ignored otherwise. |
Expand Down Expand Up @@ -57,6 +58,14 @@ This role installs nginx and configures hosts.
ssl_cert: /opt/acme/fullchain.pem
host_port: 8888
proxy_port: 9999

# Batch mode
- include_role:
name: noobient.nginx
vars:
nginx_batch:
- { domain: foo.com, mode: static, path: /data/content/foo.com }
- { domain: bar.com, mode: php, www_mode: serve }
```
## Return Values
Expand Down
28 changes: 16 additions & 12 deletions tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
---
- include_tasks: wordpress.yml
when: (noobient_nginx_wp_installed is not defined) and (mode == 'wordpress')
- include_tasks: main2.yml
vars:
domain: "{{ item.domain }}"
mode: "{{ item.mode }}"
path: "{{ item.path | default('') }}"
www_mode: "{{ item.www_mode | default('') }}"
new_domain: "{{ item.new_domain | default('') }}"
ssl_disabled: "{{ item.ssl_disabled | default('') }}"
ssl_key: "{{ item.ssl_key | default('') }}"
ssl_cert: "{{ item.ssl_cert | default('') }}"
host_port: "{{ item.host_port | default('') }}"
proxy_port: "{{ item.proxy_port | default('') }}"
loop: "{{ nginx_batch }}"
when: (nginx_batch is defined) and (nginx_batch.__class__.__name__ == 'list')

- include_tasks: php.yml
when: (noobient_nginx_php_installed is not defined) and (mode == 'php' or mode == 'wordpress')

- include_tasks: nginx.yml
when: noobient_nginx_installed is not defined

- include_tasks: config.yml
when: noobient_nginx_configured is not defined

- include_tasks: host.yml
- include_tasks: main2.yml
when: (nginx_batch is not defined) or (nginx_batch.__class__.__name__ != 'list')
14 changes: 14 additions & 0 deletions tasks/main2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
- include_tasks: wordpress.yml
when: (noobient_nginx_wp_installed is not defined) and (mode == 'wordpress')

- include_tasks: php.yml
when: (noobient_nginx_php_installed is not defined) and (mode == 'php' or mode == 'wordpress')

- include_tasks: nginx.yml
when: noobient_nginx_installed is not defined

- include_tasks: config.yml
when: noobient_nginx_configured is not defined

- include_tasks: host.yml
8 changes: 8 additions & 0 deletions tests/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,11 @@
ssl_cert: /opt/acme/foo.com.cert
host_port: 7777
proxy_port: 8888

# Test batch mode and idempotency at the same time
- include_role:
name: "{{ playbook_dir.split('/')[:-1] | last }}"
vars:
nginx_batch:
- { domain: foo3.com, mode: redirect, new_domain: bar.com, ssl_disabled: 'true' }
- { domain: foo.com, mode: proxy, ssl_key: /opt/acme/foo.com.key, ssl_cert: /opt/acme/foo.com.cert, host_port: '7777', proxy_port: '8888' }

0 comments on commit d510a2b

Please sign in to comment.