From d510a2b7b77dec46cbf2750cf9c88e2b8d9db092 Mon Sep 17 00:00:00 2001 From: Viktor Berke Date: Tue, 21 Nov 2023 13:19:33 +0100 Subject: [PATCH] Batch mode --- README.md | 9 +++++++++ tasks/main.yml | 28 ++++++++++++++++------------ tasks/main2.yml | 14 ++++++++++++++ tests/main.yml | 8 ++++++++ 4 files changed, 47 insertions(+), 12 deletions(-) create mode 100644 tasks/main2.yml diff --git a/README.md b/README.md index 4094031..3e265e8 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,7 @@ This role installs nginx and configures hosts. | Name | Required | Example | Description | |---|---|---|---| +| `nginx_batch` | no | `` | 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/` for `php`, `static`, and `wordpress`, ignored otherwise. | @@ -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 diff --git a/tasks/main.yml b/tasks/main.yml index 6e1b52a..9cf857f 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -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') diff --git a/tasks/main2.yml b/tasks/main2.yml new file mode 100644 index 0000000..6e1b52a --- /dev/null +++ b/tasks/main2.yml @@ -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 diff --git a/tests/main.yml b/tests/main.yml index 98b38dd..4282ed2 100644 --- a/tests/main.yml +++ b/tests/main.yml @@ -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' }