From f74adafe17a52574052bf0d4342667413f46813b Mon Sep 17 00:00:00 2001 From: Szymon Cader Date: Sat, 4 Jul 2020 15:46:08 +0200 Subject: [PATCH] masakra --- .yamllint | 10 + defaults/main.yml | 7 + molecule/default/converge.yml | 51 +- molecule/default/files/media.html | 1 + molecule/default/files/static.html | 1 + molecule/default/molecule.yml | 10 +- molecule/default/pytestdebug.log | 1151 ++++++++++++++++++++++++ molecule/default/tests/conftest.py | 20 + molecule/default/tests/test_default.py | 35 + tasks/catchall-vhost.yml | 43 + tasks/main.yml | 21 +- tasks/vhosts.yml | 32 +- templates/cache-snippet.j2 | 6 + templates/default-catchall.j2 | 8 + templates/django-vhost.j2 | 101 +-- templates/nginx.conf.j2 | 2 +- templates/staticpage-vhost.j2 | 34 + 17 files changed, 1460 insertions(+), 73 deletions(-) create mode 100644 molecule/default/files/media.html create mode 100644 molecule/default/files/static.html create mode 100644 molecule/default/pytestdebug.log create mode 100644 molecule/default/tests/conftest.py create mode 100644 molecule/default/tests/test_default.py create mode 100644 tasks/catchall-vhost.yml create mode 100644 templates/cache-snippet.j2 create mode 100644 templates/default-catchall.j2 create mode 100644 templates/staticpage-vhost.j2 diff --git a/.yamllint b/.yamllint index a3dbc38..2f0bba3 100644 --- a/.yamllint +++ b/.yamllint @@ -1,6 +1,16 @@ --- extends: default +ignore: | + .github rules: line-length: max: 120 level: warning + truthy: + allowed-values: + - 'true' + - 'false' + - 'yes' + - 'no' + + # ['true', 'false', 'yes', 'no'] diff --git a/defaults/main.yml b/defaults/main.yml index 0509dbe..576e53f 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -18,6 +18,13 @@ nginx_service_enabled: true nginx_conf_template: "nginx.conf.j2" nginx_vhost_template: "vhost.j2" +nginx_catchall_template: default-catchall.j2 +nginx_catchall_vhost_name: default.conf +nginx_catchall_ssl_directory: /etc/nginx/ssl +nginx_catchall_privkey: "{{ nginx_catchall_ssl_directory }}/privkey.pem" +nginx_catchall_fullchain: "{{ nginx_catchall_ssl_directory }}/fullchain.pem" +nginx_catchall_csr: "{{ nginx_catchall_ssl_directory }}/cert.csr" + nginx_worker_processes: >- "{{ ansible_processor_vcpus | default(ansible_processor_count) }}" nginx_worker_connections: "1024" diff --git a/molecule/default/converge.yml b/molecule/default/converge.yml index c3ddc5d..46a8160 100644 --- a/molecule/default/converge.yml +++ b/molecule/default/converge.yml @@ -1,19 +1,62 @@ --- - name: Converge hosts: all - + remote_user: ansible + become: yes vars: nginx_use_ppa: true nginx_remove_default_vhost: true nginx_vhosts: - - server_name: "localhost" - root: "/var/www/test" + - server_names: + - "localhost" + upstream: + name: local + server: localhost:8000 + template: django-vhost.j2 + extra_snippets: + - location: "~* /static/(.*\\.)(js|css)" + expiries: 365d + alias: "/var/www/static/$1$2" + template: cache-snippet.j2 + enable_https: true + filename: localhost-django.conf + static_root: /var/www/static/ + media_root: /var/www/media/ + certificate: /etc/nginx/ssl/fullchain.pem # selfsigned + private_key: /etc/nginx/ssl/privkey.pem # selfsigned pre_tasks: - name: Update apt cache apt: update_cache=yes cache_valid_time=600 + become: yes when: ansible_os_family == 'Debian' changed_when: false - + - name: "Create directories" + file: + path: /var/www/{{ item }} + state: directory + loop: + - static + - media + - name: "Create test file" + copy: + dest: /var/www/{{ item.directory }}/{{ item.file }} + content: "{{ item.directory }}" + loop: + - directory: static + file: static.html + - directory: static + file: cache.js + - directory: static + file: cache.css + - directory: media + file: media.html + - debug: var=ansible_python + tags: xd + - name: Run simple python server + shell: + cmd: "nohup {{ ansible_python.executable }} -m {{ 'http.server' if ansible_python.version.major == 3 else 'SimpleHTTPServer'}} &" + chdir: /tmp + tags: xd roles: - role: nginx diff --git a/molecule/default/files/media.html b/molecule/default/files/media.html new file mode 100644 index 0000000..3454702 --- /dev/null +++ b/molecule/default/files/media.html @@ -0,0 +1 @@ +media diff --git a/molecule/default/files/static.html b/molecule/default/files/static.html new file mode 100644 index 0000000..7b4d4ba --- /dev/null +++ b/molecule/default/files/static.html @@ -0,0 +1 @@ +static diff --git a/molecule/default/molecule.yml b/molecule/default/molecule.yml index 076c745..faf908c 100644 --- a/molecule/default/molecule.yml +++ b/molecule/default/molecule.yml @@ -5,7 +5,7 @@ driver: name: docker lint: | set -e - yamllint . -d "{extends: default, ignore: .github}" + yamllint . -c .yamllint ansible-lint -r . platforms: - name: ${MOLECULE_DISTRIBUTION:-debian10} @@ -15,7 +15,15 @@ platforms: - /sys/fs/cgroup:/sys/fs/cgroup:ro privileged: true pre_build_image: true + published_ports: + - 0.0.0.0:8080:443/udp + - 0.0.0.0:8080:443/tcp provisioner: name: ansible playbooks: converge: ${MOLECULE_PLAYBOOK:-converge.yml} +verifier: + name: testinfra + options: + capture: no + # n: 2 diff --git a/molecule/default/pytestdebug.log b/molecule/default/pytestdebug.log new file mode 100644 index 0000000..074cb4a --- /dev/null +++ b/molecule/default/pytestdebug.log @@ -0,0 +1,1151 @@ +versions pytest-5.4.3, py-1.8.2, python-3.8.1.final.0 +cwd=/home/sccad/infra/multiko/roles/nginx/molecule/default +args=('--connection=ansible', '--ansible-inventory=/home/sccad/.cache/molecule/nginx/default/inventory/ansible_inventory.yml', '-p', 'no:cacheprovider', '--debug', '/home/sccad/infra/multiko/roles/nginx/molecule/default/tests/test_default.py', '-vvv') + + pytest_cmdline_main [hook] + config: <_pytest.config.Config object at 0x7f4c4fbf1ee0> + pytest_plugin_registered [hook] + plugin: + manager: <_pytest.config.PytestPluginManager object at 0x7f4c4ff277f0> + finish pytest_plugin_registered --> [] [hook] + pytest_configure [hook] + config: <_pytest.config.Config object at 0x7f4c4fbf1ee0> + early skip of rewriting module: faulthandler [assertion] + pytest_configure [hook] + config: <_pytest.config.Config object at 0x7f4c4fbf1ee0> + finish pytest_configure --> [] [hook] + pytest_plugin_registered [hook] + plugin: <_pytest.faulthandler.FaultHandlerHooks object at 0x7f4c4f48daf0> + manager: <_pytest.config.PytestPluginManager object at 0x7f4c4ff277f0> + finish pytest_plugin_registered --> [] [hook] + early skip of rewriting module: pdb [assertion] + early skip of rewriting module: cmd [assertion] + early skip of rewriting module: code [assertion] + early skip of rewriting module: codeop [assertion] + pytest_plugin_registered [hook] + plugin: <_pytest.config.PytestPluginManager object at 0x7f4c4ff277f0> + manager: <_pytest.config.PytestPluginManager object at 0x7f4c4ff277f0> + finish pytest_plugin_registered --> [] [hook] + pytest_plugin_registered [hook] + plugin: <_pytest.config.Config object at 0x7f4c4fbf1ee0> + manager: <_pytest.config.PytestPluginManager object at 0x7f4c4ff277f0> + finish pytest_plugin_registered --> [] [hook] + pytest_plugin_registered [hook] + plugin: + manager: <_pytest.config.PytestPluginManager object at 0x7f4c4ff277f0> + finish pytest_plugin_registered --> [] [hook] + pytest_plugin_registered [hook] + plugin: + manager: <_pytest.config.PytestPluginManager object at 0x7f4c4ff277f0> + finish pytest_plugin_registered --> [] [hook] + pytest_plugin_registered [hook] + plugin: + manager: <_pytest.config.PytestPluginManager object at 0x7f4c4ff277f0> + finish pytest_plugin_registered --> [] [hook] + pytest_plugin_registered [hook] + plugin: + manager: <_pytest.config.PytestPluginManager object at 0x7f4c4ff277f0> + finish pytest_plugin_registered --> [] [hook] + pytest_plugin_registered [hook] + plugin: + manager: <_pytest.config.PytestPluginManager object at 0x7f4c4ff277f0> + finish pytest_plugin_registered --> [] [hook] + pytest_plugin_registered [hook] + plugin: + manager: <_pytest.config.PytestPluginManager object at 0x7f4c4ff277f0> + finish pytest_plugin_registered --> [] [hook] + pytest_plugin_registered [hook] + plugin: + manager: <_pytest.config.PytestPluginManager object at 0x7f4c4ff277f0> + finish pytest_plugin_registered --> [] [hook] + pytest_plugin_registered [hook] + plugin: + manager: <_pytest.config.PytestPluginManager object at 0x7f4c4ff277f0> + finish pytest_plugin_registered --> [] [hook] + pytest_plugin_registered [hook] + plugin: + manager: <_pytest.config.PytestPluginManager object at 0x7f4c4ff277f0> + finish pytest_plugin_registered --> [] [hook] + pytest_plugin_registered [hook] + plugin: + manager: <_pytest.config.PytestPluginManager object at 0x7f4c4ff277f0> + finish pytest_plugin_registered --> [] [hook] + pytest_plugin_registered [hook] + plugin: + manager: <_pytest.config.PytestPluginManager object at 0x7f4c4ff277f0> + finish pytest_plugin_registered --> [] [hook] + pytest_plugin_registered [hook] + plugin: + manager: <_pytest.config.PytestPluginManager object at 0x7f4c4ff277f0> + finish pytest_plugin_registered --> [] [hook] + pytest_plugin_registered [hook] + plugin: + manager: <_pytest.config.PytestPluginManager object at 0x7f4c4ff277f0> + finish pytest_plugin_registered --> [] [hook] + pytest_plugin_registered [hook] + plugin: + manager: <_pytest.config.PytestPluginManager object at 0x7f4c4ff277f0> + finish pytest_plugin_registered --> [] [hook] + pytest_plugin_registered [hook] + plugin: + manager: <_pytest.config.PytestPluginManager object at 0x7f4c4ff277f0> + finish pytest_plugin_registered --> [] [hook] + pytest_plugin_registered [hook] + plugin: + manager: <_pytest.config.PytestPluginManager object at 0x7f4c4ff277f0> + finish pytest_plugin_registered --> [] [hook] + pytest_plugin_registered [hook] + plugin: + manager: <_pytest.config.PytestPluginManager object at 0x7f4c4ff277f0> + finish pytest_plugin_registered --> [] [hook] + pytest_plugin_registered [hook] + plugin: + manager: <_pytest.config.PytestPluginManager object at 0x7f4c4ff277f0> + finish pytest_plugin_registered --> [] [hook] + pytest_plugin_registered [hook] + plugin: + manager: <_pytest.config.PytestPluginManager object at 0x7f4c4ff277f0> + finish pytest_plugin_registered --> [] [hook] + pytest_plugin_registered [hook] + plugin: + manager: <_pytest.config.PytestPluginManager object at 0x7f4c4ff277f0> + finish pytest_plugin_registered --> [] [hook] + pytest_plugin_registered [hook] + plugin: + manager: <_pytest.config.PytestPluginManager object at 0x7f4c4ff277f0> + finish pytest_plugin_registered --> [] [hook] + pytest_plugin_registered [hook] + plugin: + manager: <_pytest.config.PytestPluginManager object at 0x7f4c4ff277f0> + finish pytest_plugin_registered --> [] [hook] + pytest_plugin_registered [hook] + plugin: + manager: <_pytest.config.PytestPluginManager object at 0x7f4c4ff277f0> + finish pytest_plugin_registered --> [] [hook] + pytest_plugin_registered [hook] + plugin: + manager: <_pytest.config.PytestPluginManager object at 0x7f4c4ff277f0> + finish pytest_plugin_registered --> [] [hook] + pytest_plugin_registered [hook] + plugin: + manager: <_pytest.config.PytestPluginManager object at 0x7f4c4ff277f0> + finish pytest_plugin_registered --> [] [hook] + pytest_plugin_registered [hook] + plugin: + manager: <_pytest.config.PytestPluginManager object at 0x7f4c4ff277f0> + finish pytest_plugin_registered --> [] [hook] + pytest_plugin_registered [hook] + plugin: + manager: <_pytest.config.PytestPluginManager object at 0x7f4c4ff277f0> + finish pytest_plugin_registered --> [] [hook] + pytest_plugin_registered [hook] + plugin: + manager: <_pytest.config.PytestPluginManager object at 0x7f4c4ff277f0> + finish pytest_plugin_registered --> [] [hook] + pytest_plugin_registered [hook] + plugin: + manager: <_pytest.config.PytestPluginManager object at 0x7f4c4ff277f0> + finish pytest_plugin_registered --> [] [hook] + pytest_plugin_registered [hook] + plugin: + manager: <_pytest.config.PytestPluginManager object at 0x7f4c4ff277f0> + finish pytest_plugin_registered --> [] [hook] + pytest_plugin_registered [hook] + plugin: + manager: <_pytest.config.PytestPluginManager object at 0x7f4c4ff277f0> + finish pytest_plugin_registered --> [] [hook] + pytest_plugin_registered [hook] + plugin: + manager: <_pytest.config.PytestPluginManager object at 0x7f4c4ff277f0> + finish pytest_plugin_registered --> [] [hook] + pytest_plugin_registered [hook] + plugin: > err=> in_=> _state='suspended' _in_suspended=False> _capture_fixture=None> + manager: <_pytest.config.PytestPluginManager object at 0x7f4c4ff277f0> + finish pytest_plugin_registered --> [] [hook] + pytest_plugin_registered [hook] + plugin: + manager: <_pytest.config.PytestPluginManager object at 0x7f4c4ff277f0> + finish pytest_plugin_registered --> [] [hook] + pytest_plugin_registered [hook] + plugin: testsfailed=0 testscollected=0> + manager: <_pytest.config.PytestPluginManager object at 0x7f4c4ff277f0> + finish pytest_plugin_registered --> [] [hook] + pytest_plugin_registered [hook] + plugin: <_pytest.faulthandler.FaultHandlerHooks object at 0x7f4c4f48daf0> + manager: <_pytest.config.PytestPluginManager object at 0x7f4c4ff277f0> + finish pytest_plugin_registered --> [] [hook] + pytest_plugin_registered [hook] + plugin: <_pytest.terminal.TerminalReporter object at 0x7f4c4f3e4a00> + manager: <_pytest.config.PytestPluginManager object at 0x7f4c4ff277f0> + finish pytest_plugin_registered --> [] [hook] + pytest_plugin_registered [hook] + plugin: <_pytest.logging.LoggingPlugin object at 0x7f4c4f3a47c0> + manager: <_pytest.config.PytestPluginManager object at 0x7f4c4ff277f0> + finish pytest_plugin_registered --> [] [hook] + early skip of rewriting module: distutils [assertion] + early skip of rewriting module: distutils.dist [assertion] + early skip of rewriting module: distutils.errors [assertion] + early skip of rewriting module: distutils.fancy_getopt [assertion] + early skip of rewriting module: getopt [assertion] + early skip of rewriting module: distutils.util [assertion] + early skip of rewriting module: distutils.dep_util [assertion] + early skip of rewriting module: distutils.spawn [assertion] + early skip of rewriting module: distutils.debug [assertion] + early skip of rewriting module: distutils.log [assertion] + early skip of rewriting module: distutils.sysconfig [assertion] + early skip of rewriting module: distutils.version [assertion] + pytest_plugin_registered [hook] + plugin: + manager: <_pytest.config.PytestPluginManager object at 0x7f4c4ff277f0> + finish pytest_plugin_registered --> [] [hook] + pytest_plugin_registered [hook] + plugin: <_pytest.config.PytestPluginManager object at 0x7f4c4ff277f0> + manager: <_pytest.config.PytestPluginManager object at 0x7f4c4ff277f0> + finish pytest_plugin_registered --> [] [hook] + pytest_plugin_registered [hook] + plugin: <_pytest.config.Config object at 0x7f4c4fbf1ee0> + manager: <_pytest.config.PytestPluginManager object at 0x7f4c4ff277f0> + finish pytest_plugin_registered --> [] [hook] + pytest_plugin_registered [hook] + plugin: + manager: <_pytest.config.PytestPluginManager object at 0x7f4c4ff277f0> + finish pytest_plugin_registered --> [] [hook] + pytest_plugin_registered [hook] + plugin: + manager: <_pytest.config.PytestPluginManager object at 0x7f4c4ff277f0> + finish pytest_plugin_registered --> [] [hook] + pytest_plugin_registered [hook] + plugin: + manager: <_pytest.config.PytestPluginManager object at 0x7f4c4ff277f0> + finish pytest_plugin_registered --> [] [hook] + pytest_plugin_registered [hook] + plugin: + manager: <_pytest.config.PytestPluginManager object at 0x7f4c4ff277f0> + finish pytest_plugin_registered --> [] [hook] + pytest_plugin_registered [hook] + plugin: + manager: <_pytest.config.PytestPluginManager object at 0x7f4c4ff277f0> + finish pytest_plugin_registered --> [] [hook] + pytest_plugin_registered [hook] + plugin: + manager: <_pytest.config.PytestPluginManager object at 0x7f4c4ff277f0> + finish pytest_plugin_registered --> [] [hook] + pytest_plugin_registered [hook] + plugin: + manager: <_pytest.config.PytestPluginManager object at 0x7f4c4ff277f0> + finish pytest_plugin_registered --> [] [hook] + pytest_plugin_registered [hook] + plugin: + manager: <_pytest.config.PytestPluginManager object at 0x7f4c4ff277f0> + finish pytest_plugin_registered --> [] [hook] + pytest_plugin_registered [hook] + plugin: + manager: <_pytest.config.PytestPluginManager object at 0x7f4c4ff277f0> + finish pytest_plugin_registered --> [] [hook] + pytest_plugin_registered [hook] + plugin: + manager: <_pytest.config.PytestPluginManager object at 0x7f4c4ff277f0> + finish pytest_plugin_registered --> [] [hook] + pytest_plugin_registered [hook] + plugin: + manager: <_pytest.config.PytestPluginManager object at 0x7f4c4ff277f0> + finish pytest_plugin_registered --> [] [hook] + pytest_plugin_registered [hook] + plugin: + manager: <_pytest.config.PytestPluginManager object at 0x7f4c4ff277f0> + finish pytest_plugin_registered --> [] [hook] + pytest_plugin_registered [hook] + plugin: + manager: <_pytest.config.PytestPluginManager object at 0x7f4c4ff277f0> + finish pytest_plugin_registered --> [] [hook] + pytest_plugin_registered [hook] + plugin: + manager: <_pytest.config.PytestPluginManager object at 0x7f4c4ff277f0> + finish pytest_plugin_registered --> [] [hook] + pytest_plugin_registered [hook] + plugin: + manager: <_pytest.config.PytestPluginManager object at 0x7f4c4ff277f0> + finish pytest_plugin_registered --> [] [hook] + pytest_plugin_registered [hook] + plugin: + manager: <_pytest.config.PytestPluginManager object at 0x7f4c4ff277f0> + finish pytest_plugin_registered --> [] [hook] + pytest_plugin_registered [hook] + plugin: + manager: <_pytest.config.PytestPluginManager object at 0x7f4c4ff277f0> + finish pytest_plugin_registered --> [] [hook] + pytest_plugin_registered [hook] + plugin: + manager: <_pytest.config.PytestPluginManager object at 0x7f4c4ff277f0> + finish pytest_plugin_registered --> [] [hook] + pytest_plugin_registered [hook] + plugin: + manager: <_pytest.config.PytestPluginManager object at 0x7f4c4ff277f0> + finish pytest_plugin_registered --> [] [hook] + pytest_plugin_registered [hook] + plugin: + manager: <_pytest.config.PytestPluginManager object at 0x7f4c4ff277f0> + finish pytest_plugin_registered --> [] [hook] + pytest_plugin_registered [hook] + plugin: + manager: <_pytest.config.PytestPluginManager object at 0x7f4c4ff277f0> + finish pytest_plugin_registered --> [] [hook] + pytest_plugin_registered [hook] + plugin: + manager: <_pytest.config.PytestPluginManager object at 0x7f4c4ff277f0> + finish pytest_plugin_registered --> [] [hook] + pytest_plugin_registered [hook] + plugin: + manager: <_pytest.config.PytestPluginManager object at 0x7f4c4ff277f0> + finish pytest_plugin_registered --> [] [hook] + pytest_plugin_registered [hook] + plugin: + manager: <_pytest.config.PytestPluginManager object at 0x7f4c4ff277f0> + finish pytest_plugin_registered --> [] [hook] + pytest_plugin_registered [hook] + plugin: + manager: <_pytest.config.PytestPluginManager object at 0x7f4c4ff277f0> + finish pytest_plugin_registered --> [] [hook] + pytest_plugin_registered [hook] + plugin: + manager: <_pytest.config.PytestPluginManager object at 0x7f4c4ff277f0> + finish pytest_plugin_registered --> [] [hook] + pytest_plugin_registered [hook] + plugin: + manager: <_pytest.config.PytestPluginManager object at 0x7f4c4ff277f0> + finish pytest_plugin_registered --> [] [hook] + pytest_plugin_registered [hook] + plugin: + manager: <_pytest.config.PytestPluginManager object at 0x7f4c4ff277f0> + finish pytest_plugin_registered --> [] [hook] + pytest_plugin_registered [hook] + plugin: + manager: <_pytest.config.PytestPluginManager object at 0x7f4c4ff277f0> + finish pytest_plugin_registered --> [] [hook] + pytest_plugin_registered [hook] + plugin: + manager: <_pytest.config.PytestPluginManager object at 0x7f4c4ff277f0> + finish pytest_plugin_registered --> [] [hook] + pytest_plugin_registered [hook] + plugin: + manager: <_pytest.config.PytestPluginManager object at 0x7f4c4ff277f0> + finish pytest_plugin_registered --> [] [hook] + pytest_plugin_registered [hook] + plugin: + manager: <_pytest.config.PytestPluginManager object at 0x7f4c4ff277f0> + finish pytest_plugin_registered --> [] [hook] + pytest_plugin_registered [hook] + plugin: > err=> in_=> _state='suspended' _in_suspended=False> _capture_fixture=None> + manager: <_pytest.config.PytestPluginManager object at 0x7f4c4ff277f0> + finish pytest_plugin_registered --> [] [hook] + pytest_plugin_registered [hook] + plugin: + manager: <_pytest.config.PytestPluginManager object at 0x7f4c4ff277f0> + finish pytest_plugin_registered --> [] [hook] + pytest_plugin_registered [hook] + plugin: testsfailed=0 testscollected=0> + manager: <_pytest.config.PytestPluginManager object at 0x7f4c4ff277f0> + finish pytest_plugin_registered --> [] [hook] + pytest_plugin_registered [hook] + plugin: <_pytest.faulthandler.FaultHandlerHooks object at 0x7f4c4f48daf0> + manager: <_pytest.config.PytestPluginManager object at 0x7f4c4ff277f0> + finish pytest_plugin_registered --> [] [hook] + pytest_plugin_registered [hook] + plugin: <_pytest.terminal.TerminalReporter object at 0x7f4c4f3e4a00> + manager: <_pytest.config.PytestPluginManager object at 0x7f4c4ff277f0> + finish pytest_plugin_registered --> [] [hook] + pytest_plugin_registered [hook] + plugin: <_pytest.logging.LoggingPlugin object at 0x7f4c4f3a47c0> + manager: <_pytest.config.PytestPluginManager object at 0x7f4c4ff277f0> + finish pytest_plugin_registered --> [] [hook] + pytest_plugin_registered [hook] + plugin: + manager: <_pytest.config.PytestPluginManager object at 0x7f4c4ff277f0> + finish pytest_plugin_registered --> [] [hook] + pytest_plugin_registered [hook] + plugin: + manager: <_pytest.config.PytestPluginManager object at 0x7f4c4ff277f0> + finish pytest_plugin_registered --> [] [hook] + finish pytest_configure --> [] [hook] + pytest_sessionstart [hook] + session: testsfailed=0 testscollected=0> + early skip of rewriting module: py._std [assertion] + pytest_report_header [hook] + config: <_pytest.config.Config object at 0x7f4c4fbf1ee0> + startdir: /home/sccad/infra/multiko/roles/nginx/molecule/default + early skip of rewriting module: email.parser [assertion] + early skip of rewriting module: email.feedparser [assertion] + early skip of rewriting module: email.errors [assertion] + early skip of rewriting module: email._policybase [assertion] + early skip of rewriting module: email.header [assertion] + early skip of rewriting module: email.quoprimime [assertion] + early skip of rewriting module: email.base64mime [assertion] + early skip of rewriting module: base64 [assertion] + early skip of rewriting module: email.charset [assertion] + early skip of rewriting module: email.encoders [assertion] + early skip of rewriting module: quopri [assertion] + early skip of rewriting module: email.utils [assertion] + early skip of rewriting module: socket [assertion] + early skip of rewriting module: _socket [assertion] + early skip of rewriting module: email._parseaddr [assertion] + early skip of rewriting module: calendar [assertion] + early skip of rewriting module: email.message [assertion] + early skip of rewriting module: uu [assertion] + early skip of rewriting module: email._encoded_words [assertion] + early skip of rewriting module: email.iterators [assertion] + finish pytest_report_header --> [['rootdir: /home/sccad/infra/multiko/roles/nginx/molecule/default', 'plugins: forked-1.1.3, xdist-1.32.0, sugar-0.9.3, testinfra-5.2.1'], ['using: pytest-5.4.3 pylib-1.8.2', 'setuptools registered plugins:', ' pytest-forked-1.1.3 at /home/sccad/.virtualenvs/ansible/lib/python3.8/site-packages/pytest_forked/__init__.py', ' pytest-xdist-1.32.0 at /home/sccad/.virtualenvs/ansible/lib/python3.8/site-packages/xdist/plugin.py', ' pytest-xdist-1.32.0 at /home/sccad/.virtualenvs/ansible/lib/python3.8/site-packages/xdist/looponfail.py', ' pytest-sugar-0.9.3 at /home/sccad/.virtualenvs/ansible/lib/python3.8/site-packages/pytest_sugar.py', ' testinfra-5.2.1 at /home/sccad/.virtualenvs/ansible/lib/python3.8/site-packages/testinfra/plugin.py']] [hook] + pytest_plugin_registered [hook] + plugin: <_pytest.config.PytestPluginManager object at 0x7f4c4ff277f0> + manager: <_pytest.config.PytestPluginManager object at 0x7f4c4ff277f0> + finish pytest_plugin_registered --> [] [hook] + pytest_plugin_registered [hook] + plugin: <_pytest.config.Config object at 0x7f4c4fbf1ee0> + manager: <_pytest.config.PytestPluginManager object at 0x7f4c4ff277f0> + finish pytest_plugin_registered --> [] [hook] + pytest_plugin_registered [hook] + plugin: + manager: <_pytest.config.PytestPluginManager object at 0x7f4c4ff277f0> + finish pytest_plugin_registered --> [] [hook] + pytest_plugin_registered [hook] + plugin: + manager: <_pytest.config.PytestPluginManager object at 0x7f4c4ff277f0> + finish pytest_plugin_registered --> [] [hook] + pytest_plugin_registered [hook] + plugin: + manager: <_pytest.config.PytestPluginManager object at 0x7f4c4ff277f0> + finish pytest_plugin_registered --> [] [hook] + pytest_plugin_registered [hook] + plugin: + manager: <_pytest.config.PytestPluginManager object at 0x7f4c4ff277f0> + finish pytest_plugin_registered --> [] [hook] + pytest_plugin_registered [hook] + plugin: + manager: <_pytest.config.PytestPluginManager object at 0x7f4c4ff277f0> + finish pytest_plugin_registered --> [] [hook] + pytest_plugin_registered [hook] + plugin: + manager: <_pytest.config.PytestPluginManager object at 0x7f4c4ff277f0> + finish pytest_plugin_registered --> [] [hook] + pytest_plugin_registered [hook] + plugin: + manager: <_pytest.config.PytestPluginManager object at 0x7f4c4ff277f0> + finish pytest_plugin_registered --> [] [hook] + pytest_plugin_registered [hook] + plugin: + manager: <_pytest.config.PytestPluginManager object at 0x7f4c4ff277f0> + finish pytest_plugin_registered --> [] [hook] + pytest_plugin_registered [hook] + plugin: + manager: <_pytest.config.PytestPluginManager object at 0x7f4c4ff277f0> + finish pytest_plugin_registered --> [] [hook] + pytest_plugin_registered [hook] + plugin: + manager: <_pytest.config.PytestPluginManager object at 0x7f4c4ff277f0> + finish pytest_plugin_registered --> [] [hook] + pytest_plugin_registered [hook] + plugin: + manager: <_pytest.config.PytestPluginManager object at 0x7f4c4ff277f0> + finish pytest_plugin_registered --> [] [hook] + pytest_plugin_registered [hook] + plugin: + manager: <_pytest.config.PytestPluginManager object at 0x7f4c4ff277f0> + finish pytest_plugin_registered --> [] [hook] + pytest_plugin_registered [hook] + plugin: + manager: <_pytest.config.PytestPluginManager object at 0x7f4c4ff277f0> + finish pytest_plugin_registered --> [] [hook] + pytest_plugin_registered [hook] + plugin: + manager: <_pytest.config.PytestPluginManager object at 0x7f4c4ff277f0> + finish pytest_plugin_registered --> [] [hook] + pytest_plugin_registered [hook] + plugin: + manager: <_pytest.config.PytestPluginManager object at 0x7f4c4ff277f0> + finish pytest_plugin_registered --> [] [hook] + pytest_plugin_registered [hook] + plugin: + manager: <_pytest.config.PytestPluginManager object at 0x7f4c4ff277f0> + finish pytest_plugin_registered --> [] [hook] + pytest_plugin_registered [hook] + plugin: + manager: <_pytest.config.PytestPluginManager object at 0x7f4c4ff277f0> + finish pytest_plugin_registered --> [] [hook] + pytest_plugin_registered [hook] + plugin: + manager: <_pytest.config.PytestPluginManager object at 0x7f4c4ff277f0> + finish pytest_plugin_registered --> [] [hook] + pytest_plugin_registered [hook] + plugin: + manager: <_pytest.config.PytestPluginManager object at 0x7f4c4ff277f0> + finish pytest_plugin_registered --> [] [hook] + pytest_plugin_registered [hook] + plugin: + manager: <_pytest.config.PytestPluginManager object at 0x7f4c4ff277f0> + finish pytest_plugin_registered --> [] [hook] + pytest_plugin_registered [hook] + plugin: + manager: <_pytest.config.PytestPluginManager object at 0x7f4c4ff277f0> + finish pytest_plugin_registered --> [] [hook] + pytest_plugin_registered [hook] + plugin: + manager: <_pytest.config.PytestPluginManager object at 0x7f4c4ff277f0> + finish pytest_plugin_registered --> [] [hook] + pytest_plugin_registered [hook] + plugin: + manager: <_pytest.config.PytestPluginManager object at 0x7f4c4ff277f0> + finish pytest_plugin_registered --> [] [hook] + pytest_plugin_registered [hook] + plugin: + manager: <_pytest.config.PytestPluginManager object at 0x7f4c4ff277f0> + finish pytest_plugin_registered --> [] [hook] + pytest_plugin_registered [hook] + plugin: + manager: <_pytest.config.PytestPluginManager object at 0x7f4c4ff277f0> + finish pytest_plugin_registered --> [] [hook] + pytest_plugin_registered [hook] + plugin: + manager: <_pytest.config.PytestPluginManager object at 0x7f4c4ff277f0> + finish pytest_plugin_registered --> [] [hook] + pytest_plugin_registered [hook] + plugin: + manager: <_pytest.config.PytestPluginManager object at 0x7f4c4ff277f0> + finish pytest_plugin_registered --> [] [hook] + pytest_plugin_registered [hook] + plugin: + manager: <_pytest.config.PytestPluginManager object at 0x7f4c4ff277f0> + finish pytest_plugin_registered --> [] [hook] + pytest_plugin_registered [hook] + plugin: + manager: <_pytest.config.PytestPluginManager object at 0x7f4c4ff277f0> + finish pytest_plugin_registered --> [] [hook] + pytest_plugin_registered [hook] + plugin: + manager: <_pytest.config.PytestPluginManager object at 0x7f4c4ff277f0> + finish pytest_plugin_registered --> [] [hook] + pytest_plugin_registered [hook] + plugin: + manager: <_pytest.config.PytestPluginManager object at 0x7f4c4ff277f0> + finish pytest_plugin_registered --> [] [hook] + pytest_plugin_registered [hook] + plugin: + manager: <_pytest.config.PytestPluginManager object at 0x7f4c4ff277f0> + finish pytest_plugin_registered --> [] [hook] + pytest_plugin_registered [hook] + plugin: > err=> in_=> _state='suspended' _in_suspended=False> _capture_fixture=None> + manager: <_pytest.config.PytestPluginManager object at 0x7f4c4ff277f0> + finish pytest_plugin_registered --> [] [hook] + pytest_plugin_registered [hook] + plugin: + manager: <_pytest.config.PytestPluginManager object at 0x7f4c4ff277f0> + finish pytest_plugin_registered --> [] [hook] + pytest_plugin_registered [hook] + plugin: testsfailed=0 testscollected=0> + manager: <_pytest.config.PytestPluginManager object at 0x7f4c4ff277f0> + finish pytest_plugin_registered --> [] [hook] + pytest_plugin_registered [hook] + plugin: <_pytest.faulthandler.FaultHandlerHooks object at 0x7f4c4f48daf0> + manager: <_pytest.config.PytestPluginManager object at 0x7f4c4ff277f0> + finish pytest_plugin_registered --> [] [hook] + pytest_plugin_registered [hook] + plugin: <_pytest.terminal.TerminalReporter object at 0x7f4c4f3e4a00> + manager: <_pytest.config.PytestPluginManager object at 0x7f4c4ff277f0> + finish pytest_plugin_registered --> [] [hook] + pytest_plugin_registered [hook] + plugin: <_pytest.logging.LoggingPlugin object at 0x7f4c4f3a47c0> + manager: <_pytest.config.PytestPluginManager object at 0x7f4c4ff277f0> + finish pytest_plugin_registered --> [] [hook] + pytest_plugin_registered [hook] + plugin: + manager: <_pytest.config.PytestPluginManager object at 0x7f4c4ff277f0> + finish pytest_plugin_registered --> [] [hook] + pytest_plugin_registered [hook] + plugin: + manager: <_pytest.config.PytestPluginManager object at 0x7f4c4ff277f0> + finish pytest_plugin_registered --> [] [hook] + pytest_plugin_registered [hook] + plugin: <_pytest.fixtures.FixtureManager object at 0x7f4c4f378100> + manager: <_pytest.config.PytestPluginManager object at 0x7f4c4ff277f0> + finish pytest_plugin_registered --> [] [hook] + finish pytest_sessionstart --> [] [hook] + pytest_collection [hook] + session: testsfailed=0 testscollected=0> + perform_collect testsfailed=0 testscollected=0> ['/home/sccad/infra/multiko/roles/nginx/molecule/default/tests/test_default.py'] [collection] + pytest_collectstart [hook] + collector: testsfailed=0 testscollected=0> + finish pytest_collectstart --> [] [hook] + pytest_make_collect_report [hook] + collector: testsfailed=0 testscollected=0> + processing argument (local('/home/sccad/infra/multiko/roles/nginx/molecule/default/tests/test_default.py'), []) [collection] + pytest_collect_file [hook] + path: /home/sccad/infra/multiko/roles/nginx/molecule/default/tests/test_default.py + parent: testsfailed=0 testscollected=0> + pytest_pycollect_makemodule [hook] + path: /home/sccad/infra/multiko/roles/nginx/molecule/default/tests/test_default.py + parent: testsfailed=0 testscollected=0> + finish pytest_pycollect_makemodule --> [hook] + finish pytest_collect_file --> [] [hook] + matchnodes [] [] [collection] + matchnodes finished -> 1 nodes [collection] + finish pytest_make_collect_report --> [hook] + pytest_collectreport [hook] + report: + finish pytest_collectreport --> [] [hook] + genitems [collection] + pytest_collectstart [hook] + collector: + finish pytest_collectstart --> [] [hook] + pytest_make_collect_report [hook] + collector: + find_module called for: test_default [assertion] + matched test file (was specified on cmdline): '/home/sccad/infra/multiko/roles/nginx/molecule/default/tests/test_default.py' [assertion] + found cached rewritten pyc for /home/sccad/infra/multiko/roles/nginx/molecule/default/tests/test_default.py [assertion] + early skip of rewriting module: requests [assertion] + early skip of rewriting module: urllib3 [assertion] + early skip of rewriting module: urllib3.connectionpool [assertion] + early skip of rewriting module: urllib3.exceptions [assertion] + early skip of rewriting module: urllib3.packages [assertion] + early skip of rewriting module: urllib3.packages.ssl_match_hostname [assertion] + early skip of rewriting module: ssl [assertion] + early skip of rewriting module: _ssl [assertion] + early skip of rewriting module: urllib3.packages.six [assertion] + early skip of rewriting module: urllib3.packages.six.moves [assertion] + early skip of rewriting module: urllib3.packages.six.moves.http_client [assertion] + early skip of rewriting module: http [assertion] + early skip of rewriting module: http.client [assertion] + early skip of rewriting module: queue [assertion] + early skip of rewriting module: _queue [assertion] + early skip of rewriting module: urllib3.connection [assertion] + early skip of rewriting module: urllib3.util [assertion] + early skip of rewriting module: urllib3.util.connection [assertion] + early skip of rewriting module: urllib3.util.wait [assertion] + early skip of rewriting module: urllib3.contrib [assertion] + early skip of rewriting module: urllib3.contrib._appengine_environ [assertion] + early skip of rewriting module: urllib3.util.request [assertion] + early skip of rewriting module: brotli [assertion] + early skip of rewriting module: urllib3.util.response [assertion] + early skip of rewriting module: urllib3.util.ssl_ [assertion] + early skip of rewriting module: hmac [assertion] + early skip of rewriting module: _hashlib [assertion] + early skip of rewriting module: hashlib [assertion] + early skip of rewriting module: _blake2 [assertion] + early skip of rewriting module: _sha3 [assertion] + early skip of rewriting module: urllib3.util.url [assertion] + early skip of rewriting module: urllib3.util.timeout [assertion] + early skip of rewriting module: urllib3.util.retry [assertion] + early skip of rewriting module: urllib3._collections [assertion] + early skip of rewriting module: urllib3.request [assertion] + early skip of rewriting module: urllib3.filepost [assertion] + early skip of rewriting module: urllib3.fields [assertion] + early skip of rewriting module: mimetypes [assertion] + early skip of rewriting module: winreg [assertion] + early skip of rewriting module: urllib3.packages.six.moves.urllib [assertion] + early skip of rewriting module: urllib3.packages.six.moves.urllib.parse [assertion] + early skip of rewriting module: urllib3.response [assertion] + early skip of rewriting module: brotli [assertion] + early skip of rewriting module: urllib3.util.queue [assertion] + early skip of rewriting module: urllib3.poolmanager [assertion] + early skip of rewriting module: chardet [assertion] + early skip of rewriting module: chardet.compat [assertion] + early skip of rewriting module: chardet.universaldetector [assertion] + early skip of rewriting module: chardet.charsetgroupprober [assertion] + early skip of rewriting module: chardet.enums [assertion] + early skip of rewriting module: chardet.charsetprober [assertion] + early skip of rewriting module: chardet.escprober [assertion] + early skip of rewriting module: chardet.codingstatemachine [assertion] + early skip of rewriting module: chardet.escsm [assertion] + early skip of rewriting module: chardet.latin1prober [assertion] + early skip of rewriting module: chardet.mbcsgroupprober [assertion] + early skip of rewriting module: chardet.utf8prober [assertion] + early skip of rewriting module: chardet.mbcssm [assertion] + early skip of rewriting module: chardet.sjisprober [assertion] + early skip of rewriting module: chardet.mbcharsetprober [assertion] + early skip of rewriting module: chardet.chardistribution [assertion] + early skip of rewriting module: chardet.euctwfreq [assertion] + early skip of rewriting module: chardet.euckrfreq [assertion] + early skip of rewriting module: chardet.gb2312freq [assertion] + early skip of rewriting module: chardet.big5freq [assertion] + early skip of rewriting module: chardet.jisfreq [assertion] + early skip of rewriting module: chardet.jpcntx [assertion] + early skip of rewriting module: chardet.eucjpprober [assertion] + early skip of rewriting module: chardet.gb2312prober [assertion] + early skip of rewriting module: chardet.euckrprober [assertion] + early skip of rewriting module: chardet.cp949prober [assertion] + early skip of rewriting module: chardet.big5prober [assertion] + early skip of rewriting module: chardet.euctwprober [assertion] + early skip of rewriting module: chardet.sbcsgroupprober [assertion] + early skip of rewriting module: chardet.sbcharsetprober [assertion] + early skip of rewriting module: chardet.langcyrillicmodel [assertion] + early skip of rewriting module: chardet.langgreekmodel [assertion] + early skip of rewriting module: chardet.langbulgarianmodel [assertion] + early skip of rewriting module: chardet.langthaimodel [assertion] + early skip of rewriting module: chardet.langhebrewmodel [assertion] + early skip of rewriting module: chardet.hebrewprober [assertion] + early skip of rewriting module: chardet.langturkishmodel [assertion] + early skip of rewriting module: chardet.version [assertion] + early skip of rewriting module: requests.exceptions [assertion] + early skip of rewriting module: requests.__version__ [assertion] + early skip of rewriting module: requests.utils [assertion] + early skip of rewriting module: requests.certs [assertion] + early skip of rewriting module: certifi [assertion] + early skip of rewriting module: certifi.core [assertion] + early skip of rewriting module: importlib.resources [assertion] + early skip of rewriting module: requests._internal_utils [assertion] + early skip of rewriting module: requests.compat [assertion] + early skip of rewriting module: simplejson [assertion] + early skip of rewriting module: json [assertion] + early skip of rewriting module: json.decoder [assertion] + early skip of rewriting module: json.scanner [assertion] + early skip of rewriting module: _json [assertion] + early skip of rewriting module: json.encoder [assertion] + early skip of rewriting module: urllib.request [assertion] + early skip of rewriting module: urllib.error [assertion] + early skip of rewriting module: urllib.response [assertion] + early skip of rewriting module: http.cookiejar [assertion] + early skip of rewriting module: http.cookies [assertion] + early skip of rewriting module: requests.cookies [assertion] + early skip of rewriting module: requests.structures [assertion] + early skip of rewriting module: requests.packages [assertion] + early skip of rewriting module: idna [assertion] + early skip of rewriting module: idna.package_data [assertion] + early skip of rewriting module: idna.core [assertion] + early skip of rewriting module: idna.idnadata [assertion] + early skip of rewriting module: idna.intranges [assertion] + early skip of rewriting module: requests.models [assertion] + early skip of rewriting module: encodings.idna [assertion] + early skip of rewriting module: stringprep [assertion] + early skip of rewriting module: requests.hooks [assertion] + early skip of rewriting module: requests.auth [assertion] + early skip of rewriting module: requests.status_codes [assertion] + early skip of rewriting module: requests.api [assertion] + early skip of rewriting module: requests.sessions [assertion] + early skip of rewriting module: requests.adapters [assertion] + early skip of rewriting module: urllib3.contrib.socks [assertion] + early skip of rewriting module: socks [assertion] + pytest_pycollect_makeitem [hook] + collector: + name: __name__ + obj: test_default + finish pytest_pycollect_makeitem --> None [hook] + pytest_pycollect_makeitem [hook] + collector: + name: __doc__ + obj: Role testing files using testinfra. + finish pytest_pycollect_makeitem --> None [hook] + pytest_pycollect_makeitem [hook] + collector: + name: __package__ + obj: + finish pytest_pycollect_makeitem --> None [hook] + pytest_pycollect_makeitem [hook] + collector: + name: __loader__ + obj: <_pytest.assertion.rewrite.AssertionRewritingHook object at 0x7f4c4f49a610> + finish pytest_pycollect_makeitem --> None [hook] + pytest_pycollect_makeitem [hook] + collector: + name: __spec__ + obj: ModuleSpec(name='test_default', loader=<_pytest.assertion.rewrite.AssertionRewritingHook object at 0x7f4c4f49a610>, origin='/home/sccad/infra/multiko/roles/nginx/molecule/default/tests/test_default.py') + finish pytest_pycollect_makeitem --> None [hook] + pytest_pycollect_makeitem [hook] + collector: + name: __file__ + obj: /home/sccad/infra/multiko/roles/nginx/molecule/default/tests/test_default.py + finish pytest_pycollect_makeitem --> None [hook] + pytest_pycollect_makeitem [hook] + collector: + name: __cached__ + obj: /home/sccad/infra/multiko/roles/nginx/molecule/default/tests/__pycache__/test_default.cpython-38.pyc + finish pytest_pycollect_makeitem --> None [hook] + pytest_pycollect_makeitem [hook] + collector: + name: __builtins__ + obj: {'__name__': 'builtins', '__doc__': "Built-in functions, exceptions, and other objects.\n\nNoteworthy: None is the `nil' object; Ellipsis represents `...' in slices.", '__package__': '', '__loader__': , '__spec__': ModuleSpec(name='builtins', loader=), '__build_class__': , '__import__': , 'abs': , 'all': , 'any': , 'ascii': , 'bin': , 'breakpoint': , 'callable': , 'chr': , 'compile': , 'delattr': , 'dir': , 'divmod': , 'eval': , 'exec': , 'format': , 'getattr': , 'globals': , 'hasattr': , 'hash': , 'hex': , 'id': , 'input': , 'isinstance': , 'issubclass': , 'iter': , 'len': , 'locals': , 'max': , 'min': , 'next': , 'oct': , 'ord': , 'pow': , 'print': , 'repr': , 'round': , 'setattr': , 'sorted': , 'sum': , 'vars': , 'None': None, 'Ellipsis': Ellipsis, 'NotImplemented': NotImplemented, 'False': False, 'True': True, 'bool': , 'memoryview': , 'bytearray': , 'bytes': , 'classmethod': , 'complex': , 'dict': , 'enumerate': , 'filter': , 'float': , 'frozenset': , 'property': , 'int': , 'list': , 'map': , 'object': , 'range': , 'reversed': , 'set': , 'slice': , 'staticmethod': , 'str': , 'super': , 'tuple': , 'type': , 'zip': , '__debug__': True, 'BaseException': , 'Exception': , 'TypeError': , 'StopAsyncIteration': , 'StopIteration': , 'GeneratorExit': , 'SystemExit': , 'KeyboardInterrupt': , 'ImportError': , 'ModuleNotFoundError': , 'OSError': , 'EnvironmentError': , 'IOError': , 'EOFError': , 'RuntimeError': , 'RecursionError': , 'NotImplementedError': , 'NameError': , 'UnboundLocalError': , 'AttributeError': , 'SyntaxError': , 'IndentationError': , 'TabError': , 'LookupError': , 'IndexError': , 'KeyError': , 'ValueError': , 'UnicodeError': , 'UnicodeEncodeError': , 'UnicodeDecodeError': , 'UnicodeTranslateError': , 'AssertionError': , 'ArithmeticError': , 'FloatingPointError': , 'OverflowError': , 'ZeroDivisionError': , 'SystemError': , 'ReferenceError': , 'MemoryError': , 'BufferError': , 'Warning': , 'UserWarning': , 'DeprecationWarning': , 'PendingDeprecationWarning': , 'SyntaxWarning': , 'RuntimeWarning': , 'FutureWarning': , 'ImportWarning': , 'UnicodeWarning': , 'BytesWarning': , 'ResourceWarning': , 'ConnectionError': , 'BlockingIOError': , 'BrokenPipeError': , 'ChildProcessError': , 'ConnectionAbortedError': , 'ConnectionRefusedError': , 'ConnectionResetError': , 'FileExistsError': , 'FileNotFoundError': , 'IsADirectoryError': , 'NotADirectoryError': , 'InterruptedError': , 'PermissionError': , 'ProcessLookupError': , 'TimeoutError': , 'open': , 'quit': Use quit() or Ctrl-D (i.e. EOF) to exit, 'exit': Use exit() or Ctrl-D (i.e. EOF) to exit, 'copyright': Copyright (c) 2001-2019 Python Software Foundation. +All Rights Reserved. + +Copyright (c) 2000 BeOpen.com. +All Rights Reserved. + +Copyright (c) 1995-2001 Corporation for National Research Initiatives. +All Rights Reserved. + +Copyright (c) 1991-1995 Stichting Mathematisch Centrum, Amsterdam. +All Rights Reserved., 'credits': Thanks to CWI, CNRI, BeOpen.com, Zope Corporation and a cast of thousands + for supporting Python development. See www.python.org for more information., 'license': See https://www.python.org/psf/license/, 'help': Type help() for interactive help, or help(object) for help about object.} + finish pytest_pycollect_makeitem --> None [hook] + pytest_pycollect_makeitem [hook] + collector: + name: @py_builtins + obj: + finish pytest_pycollect_makeitem --> None [hook] + pytest_pycollect_makeitem [hook] + collector: + name: @pytest_ar + obj: + finish pytest_pycollect_makeitem --> None [hook] + pytest_pycollect_makeitem [hook] + collector: + name: pytest + obj: + finish pytest_pycollect_makeitem --> None [hook] + pytest_pycollect_makeitem [hook] + collector: + name: requests + obj: + finish pytest_pycollect_makeitem --> None [hook] + pytest_pycollect_makeitem [hook] + collector: + name: test_is_postgresql_runnnig_and_enabled + obj: + pytest_generate_tests [hook] + metafunc: <_pytest.python.Metafunc object at 0x7f4c4f0fb3d0> + matched marked file 'testinfra.backend.ansible' (from 'testinfra') [assertion] + find_module called for: testinfra.backend.ansible [assertion] + found cached rewritten pyc for /home/sccad/.virtualenvs/ansible/lib/python3.8/site-packages/testinfra/backend/ansible.py [assertion] + matched marked file 'testinfra.backend.base' (from 'testinfra') [assertion] + find_module called for: testinfra.backend.base [assertion] + found cached rewritten pyc for /home/sccad/.virtualenvs/ansible/lib/python3.8/site-packages/testinfra/backend/base.py [assertion] + early skip of rewriting module: pipes [assertion] + matched marked file 'testinfra.utils' (from 'testinfra') [assertion] + find_module called for: testinfra.utils [assertion] + found cached rewritten pyc for /home/sccad/.virtualenvs/ansible/lib/python3.8/site-packages/testinfra/utils/__init__.py [assertion] + matched marked file 'testinfra.utils.ansible_runner' (from 'testinfra') [assertion] + find_module called for: testinfra.utils.ansible_runner [assertion] + found cached rewritten pyc for /home/sccad/.virtualenvs/ansible/lib/python3.8/site-packages/testinfra/utils/ansible_runner.py [assertion] + early skip of rewriting module: ipaddress [assertion] + matched marked file 'testinfra.backend.local' (from 'testinfra') [assertion] + find_module called for: testinfra.backend.local [assertion] + found cached rewritten pyc for /home/sccad/.virtualenvs/ansible/lib/python3.8/site-packages/testinfra/backend/local.py [assertion] + early skip of rewriting module: encodings.unicode_escape [assertion] + finish pytest_generate_tests --> [] [hook] + finish pytest_pycollect_makeitem --> [] [hook] + pytest_pycollect_makeitem [hook] + collector: + name: test_statics_location_is_accessible + obj: + pytest_generate_tests [hook] + metafunc: <_pytest.python.Metafunc object at 0x7f4c4f0fb640> + pytest_make_parametrize_id [hook] + config: <_pytest.config.Config object at 0x7f4c4fbf1ee0> + val: static/static.html + argname: path + finish pytest_make_parametrize_id --> None [hook] + pytest_make_parametrize_id [hook] + config: <_pytest.config.Config object at 0x7f4c4fbf1ee0> + val: b'static' + argname: content + finish pytest_make_parametrize_id --> None [hook] + pytest_make_parametrize_id [hook] + config: <_pytest.config.Config object at 0x7f4c4fbf1ee0> + val: media/media.html + argname: path + finish pytest_make_parametrize_id --> None [hook] + pytest_make_parametrize_id [hook] + config: <_pytest.config.Config object at 0x7f4c4fbf1ee0> + val: b'media' + argname: content + finish pytest_make_parametrize_id --> None [hook] + finish pytest_generate_tests --> [] [hook] + finish pytest_pycollect_makeitem --> [, ] [hook] + pytest_pycollect_makeitem [hook] + collector: + name: __repr__ + obj: + finish pytest_pycollect_makeitem --> None [hook] + pytest_pycollect_makeitem [hook] + collector: + name: __getattribute__ + obj: + finish pytest_pycollect_makeitem --> None [hook] + pytest_pycollect_makeitem [hook] + collector: + name: __setattr__ + obj: + finish pytest_pycollect_makeitem --> None [hook] + pytest_pycollect_makeitem [hook] + collector: + name: __delattr__ + obj: + finish pytest_pycollect_makeitem --> None [hook] + pytest_pycollect_makeitem [hook] + collector: + name: __init__ + obj: + finish pytest_pycollect_makeitem --> None [hook] + pytest_pycollect_makeitem [hook] + collector: + name: __new__ + obj: + finish pytest_pycollect_makeitem --> None [hook] + pytest_pycollect_makeitem [hook] + collector: + name: __dir__ + obj: + finish pytest_pycollect_makeitem --> None [hook] + pytest_pycollect_makeitem [hook] + collector: + name: __dict__ + obj: + finish pytest_pycollect_makeitem --> None [hook] + pytest_pycollect_makeitem [hook] + collector: + name: __hash__ + obj: + finish pytest_pycollect_makeitem --> None [hook] + pytest_pycollect_makeitem [hook] + collector: + name: __str__ + obj: + finish pytest_pycollect_makeitem --> None [hook] + pytest_pycollect_makeitem [hook] + collector: + name: __lt__ + obj: + finish pytest_pycollect_makeitem --> None [hook] + pytest_pycollect_makeitem [hook] + collector: + name: __le__ + obj: + finish pytest_pycollect_makeitem --> None [hook] + pytest_pycollect_makeitem [hook] + collector: + name: __eq__ + obj: + finish pytest_pycollect_makeitem --> None [hook] + pytest_pycollect_makeitem [hook] + collector: + name: __ne__ + obj: + finish pytest_pycollect_makeitem --> None [hook] + pytest_pycollect_makeitem [hook] + collector: + name: __gt__ + obj: + finish pytest_pycollect_makeitem --> None [hook] + pytest_pycollect_makeitem [hook] + collector: + name: __ge__ + obj: + finish pytest_pycollect_makeitem --> None [hook] + pytest_pycollect_makeitem [hook] + collector: + name: __reduce_ex__ + obj: + finish pytest_pycollect_makeitem --> None [hook] + pytest_pycollect_makeitem [hook] + collector: + name: __reduce__ + obj: + finish pytest_pycollect_makeitem --> None [hook] + pytest_pycollect_makeitem [hook] + collector: + name: __subclasshook__ + obj: + finish pytest_pycollect_makeitem --> None [hook] + pytest_pycollect_makeitem [hook] + collector: + name: __init_subclass__ + obj: + finish pytest_pycollect_makeitem --> None [hook] + pytest_pycollect_makeitem [hook] + collector: + name: __format__ + obj: + finish pytest_pycollect_makeitem --> None [hook] + pytest_pycollect_makeitem [hook] + collector: + name: __sizeof__ + obj: + finish pytest_pycollect_makeitem --> None [hook] + pytest_pycollect_makeitem [hook] + collector: + name: __class__ + obj: + finish pytest_pycollect_makeitem --> None [hook] + finish pytest_make_collect_report --> [hook] + genitems [collection] + pytest_itemcollected [hook] + item: + finish pytest_itemcollected --> [] [hook] + genitems [collection] + pytest_itemcollected [hook] + item: + finish pytest_itemcollected --> [] [hook] + genitems [collection] + pytest_itemcollected [hook] + item: + finish pytest_itemcollected --> [] [hook] + pytest_collectreport [hook] + report: + finish pytest_collectreport --> [] [hook] + pytest_collection_modifyitems [hook] + session: testsfailed=0 testscollected=0> + config: <_pytest.config.Config object at 0x7f4c4fbf1ee0> + items: [, , ] + finish pytest_collection_modifyitems --> [] [hook] + pytest_collection_finish [hook] + session: testsfailed=0 testscollected=0> + pytest_report_collectionfinish [hook] + config: <_pytest.config.Config object at 0x7f4c4fbf1ee0> + startdir: /home/sccad/infra/multiko/roles/nginx/molecule/default + items: [, , ] + finish pytest_report_collectionfinish --> [] [hook] + finish pytest_collection_finish --> [] [hook] + finish pytest_collection --> [, , ] [hook] + pytest_runtestloop [hook] + session: testsfailed=0 testscollected=3> + pytest_runtest_protocol [hook] + item: + nextitem: + pytest_runtest_logstart [hook] + nodeid: tests/test_default.py::test_is_postgresql_runnnig_and_enabled[ansible://debian10] + location: ('tests/test_default.py', 4, 'test_is_postgresql_runnnig_and_enabled[ansible://debian10]') + finish pytest_runtest_logstart --> [] [hook] + pytest_runtest_setup [hook] + item: + pytest_fixture_setup [hook] + fixturedef: + request: > + finish pytest_fixture_setup --> [hook] + pytest_fixture_setup [hook] + fixturedef: + request: > + finish pytest_fixture_setup --> [hook] + finish pytest_runtest_setup --> [] [hook] + pytest_runtest_makereport [hook] + item: + call: + finish pytest_runtest_makereport --> [hook] + pytest_runtest_logreport [hook] + report: + finish pytest_runtest_logreport --> [] [hook] + pytest_runtest_call [hook] + item: + pytest_pyfunc_call [hook] + pyfuncitem: + matched marked file 'testinfra.modules.service' (from 'testinfra') [assertion] + find_module called for: testinfra.modules.service [assertion] + found cached rewritten pyc for /home/sccad/.virtualenvs/ansible/lib/python3.8/site-packages/testinfra/modules/service.py [assertion] + matched marked file 'testinfra.modules.base' (from 'testinfra') [assertion] + find_module called for: testinfra.modules.base [assertion] + found cached rewritten pyc for /home/sccad/.virtualenvs/ansible/lib/python3.8/site-packages/testinfra/modules/base.py [assertion] + matched marked file 'testinfra.modules.systeminfo' (from 'testinfra') [assertion] + find_module called for: testinfra.modules.systeminfo [assertion] + found cached rewritten pyc for /home/sccad/.virtualenvs/ansible/lib/python3.8/site-packages/testinfra/modules/systeminfo.py [assertion] + matched marked file 'testinfra.backend.docker' (from 'testinfra') [assertion] + find_module called for: testinfra.backend.docker [assertion] + found cached rewritten pyc for /home/sccad/.virtualenvs/ansible/lib/python3.8/site-packages/testinfra/backend/docker.py [assertion] + matched marked file 'testinfra.modules.file' (from 'testinfra') [assertion] + find_module called for: testinfra.modules.file [assertion] + found cached rewritten pyc for /home/sccad/.virtualenvs/ansible/lib/python3.8/site-packages/testinfra/modules/file.py [assertion] + finish pytest_pyfunc_call --> True [hook] + finish pytest_runtest_call --> [] [hook] + pytest_runtest_makereport [hook] + item: + call: + finish pytest_runtest_makereport --> [hook] + pytest_runtest_logreport [hook] + report: + pytest_internalerror [hook] + excrepr: Traceback (most recent call last): + File "/home/sccad/.virtualenvs/ansible/lib/python3.8/site-packages/_pytest/main.py", line 191, in wrap_session + session.exitstatus = doit(config, session) or 0 + File "/home/sccad/.virtualenvs/ansible/lib/python3.8/site-packages/_pytest/main.py", line 247, in _main + config.hook.pytest_runtestloop(session=session) + File "/home/sccad/.virtualenvs/ansible/lib/python3.8/site-packages/pluggy/hooks.py", line 286, in __call__ + return self._hookexec(self, self.get_hookimpls(), kwargs) + File "/home/sccad/.virtualenvs/ansible/lib/python3.8/site-packages/pluggy/manager.py", line 93, in _hookexec + return self._inner_hookexec(hook, methods, kwargs) + File "/home/sccad/.virtualenvs/ansible/lib/python3.8/site-packages/pluggy/manager.py", line 337, in traced_hookexec + return outcome.get_result() + File "/home/sccad/.virtualenvs/ansible/lib/python3.8/site-packages/pluggy/callers.py", line 80, in get_result + raise ex[1].with_traceback(ex[2]) + File "/home/sccad/.virtualenvs/ansible/lib/python3.8/site-packages/pluggy/callers.py", line 52, in from_call + result = func() + File "/home/sccad/.virtualenvs/ansible/lib/python3.8/site-packages/pluggy/manager.py", line 335, in + outcome = _Result.from_call(lambda: oldcall(hook, hook_impls, kwargs)) + File "/home/sccad/.virtualenvs/ansible/lib/python3.8/site-packages/pluggy/manager.py", line 84, in + self._inner_hookexec = lambda hook, methods, kwargs: hook.multicall( + File "/home/sccad/.virtualenvs/ansible/lib/python3.8/site-packages/pluggy/callers.py", line 208, in _multicall + return outcome.get_result() + File "/home/sccad/.virtualenvs/ansible/lib/python3.8/site-packages/pluggy/callers.py", line 80, in get_result + raise ex[1].with_traceback(ex[2]) + File "/home/sccad/.virtualenvs/ansible/lib/python3.8/site-packages/pluggy/callers.py", line 187, in _multicall + res = hook_impl.function(*args) + File "/home/sccad/.virtualenvs/ansible/lib/python3.8/site-packages/_pytest/main.py", line 272, in pytest_runtestloop + item.config.hook.pytest_runtest_protocol(item=item, nextitem=nextitem) + File "/home/sccad/.virtualenvs/ansible/lib/python3.8/site-packages/pluggy/hooks.py", line 286, in __call__ + return self._hookexec(self, self.get_hookimpls(), kwargs) + File "/home/sccad/.virtualenvs/ansible/lib/python3.8/site-packages/pluggy/manager.py", line 93, in _hookexec + return self._inner_hookexec(hook, methods, kwargs) + File "/home/sccad/.virtualenvs/ansible/lib/python3.8/site-packages/pluggy/manager.py", line 337, in traced_hookexec + return outcome.get_result() + File "/home/sccad/.virtualenvs/ansible/lib/python3.8/site-packages/pluggy/callers.py", line 80, in get_result + raise ex[1].with_traceback(ex[2]) + File "/home/sccad/.virtualenvs/ansible/lib/python3.8/site-packages/pluggy/callers.py", line 52, in from_call + result = func() + File "/home/sccad/.virtualenvs/ansible/lib/python3.8/site-packages/pluggy/manager.py", line 335, in + outcome = _Result.from_call(lambda: oldcall(hook, hook_impls, kwargs)) + File "/home/sccad/.virtualenvs/ansible/lib/python3.8/site-packages/pluggy/manager.py", line 84, in + self._inner_hookexec = lambda hook, methods, kwargs: hook.multicall( + File "/home/sccad/.virtualenvs/ansible/lib/python3.8/site-packages/pluggy/callers.py", line 208, in _multicall + return outcome.get_result() + File "/home/sccad/.virtualenvs/ansible/lib/python3.8/site-packages/pluggy/callers.py", line 80, in get_result + raise ex[1].with_traceback(ex[2]) + File "/home/sccad/.virtualenvs/ansible/lib/python3.8/site-packages/pluggy/callers.py", line 187, in _multicall + res = hook_impl.function(*args) + File "/home/sccad/.virtualenvs/ansible/lib/python3.8/site-packages/_pytest/runner.py", line 85, in pytest_runtest_protocol + runtestprotocol(item, nextitem=nextitem) + File "/home/sccad/.virtualenvs/ansible/lib/python3.8/site-packages/_pytest/runner.py", line 100, in runtestprotocol + reports.append(call_and_report(item, "call", log)) + File "/home/sccad/.virtualenvs/ansible/lib/python3.8/site-packages/_pytest/runner.py", line 190, in call_and_report + hook.pytest_runtest_logreport(report=report) + File "/home/sccad/.virtualenvs/ansible/lib/python3.8/site-packages/pluggy/hooks.py", line 286, in __call__ + return self._hookexec(self, self.get_hookimpls(), kwargs) + File "/home/sccad/.virtualenvs/ansible/lib/python3.8/site-packages/pluggy/manager.py", line 93, in _hookexec + return self._inner_hookexec(hook, methods, kwargs) + File "/home/sccad/.virtualenvs/ansible/lib/python3.8/site-packages/pluggy/manager.py", line 337, in traced_hookexec + return outcome.get_result() + File "/home/sccad/.virtualenvs/ansible/lib/python3.8/site-packages/pluggy/callers.py", line 80, in get_result + raise ex[1].with_traceback(ex[2]) + File "/home/sccad/.virtualenvs/ansible/lib/python3.8/site-packages/pluggy/callers.py", line 52, in from_call + result = func() + File "/home/sccad/.virtualenvs/ansible/lib/python3.8/site-packages/pluggy/manager.py", line 335, in + outcome = _Result.from_call(lambda: oldcall(hook, hook_impls, kwargs)) + File "/home/sccad/.virtualenvs/ansible/lib/python3.8/site-packages/pluggy/manager.py", line 84, in + self._inner_hookexec = lambda hook, methods, kwargs: hook.multicall( + File "/home/sccad/.virtualenvs/ansible/lib/python3.8/site-packages/pluggy/callers.py", line 208, in _multicall + return outcome.get_result() + File "/home/sccad/.virtualenvs/ansible/lib/python3.8/site-packages/pluggy/callers.py", line 80, in get_result + raise ex[1].with_traceback(ex[2]) + File "/home/sccad/.virtualenvs/ansible/lib/python3.8/site-packages/pluggy/callers.py", line 187, in _multicall + res = hook_impl.function(*args) + File "/home/sccad/.virtualenvs/ansible/lib/python3.8/site-packages/pytest_sugar.py", line 441, in pytest_runtest_logreport + self.begin_new_line(report, print_filename=True) + File "/home/sccad/.virtualenvs/ansible/lib/python3.8/site-packages/pytest_sugar.py", line 391, in begin_new_line + self.write("\r\n") + File "/home/sccad/.virtualenvs/ansible/lib/python3.8/site-packages/_pytest/terminal.py", line 363, in write + self._tw.write(content, **markup) + File "/home/sccad/.virtualenvs/ansible/lib/python3.8/site-packages/py/_io/terminalwriter.py", line 256, in write + write_out(self._file, markupmsg) + File "/home/sccad/.virtualenvs/ansible/lib/python3.8/site-packages/py/_io/terminalwriter.py", line 406, in write_out + fil.write(msg) +OSError: [Errno 5] Input/output error + excinfo: + pytest_sessionfinish [hook] + session: testsfailed=0 testscollected=3> + exitstatus: ExitCode.INTERNAL_ERROR + pytest_fixture_post_finalizer [hook] + fixturedef: + request: > + finish pytest_fixture_post_finalizer --> [] [hook] + pytest_fixture_post_finalizer [hook] + fixturedef: + request: > + finish pytest_fixture_post_finalizer --> [] [hook] + pytest_fixture_post_finalizer [hook] + fixturedef: + request: > + finish pytest_fixture_post_finalizer --> [] [hook] + pytest_unconfigure [hook] + config: <_pytest.config.Config object at 0x7f4c4fbf1ee0> + finish pytest_unconfigure --> [] [hook] diff --git a/molecule/default/tests/conftest.py b/molecule/default/tests/conftest.py new file mode 100644 index 0000000..ba0f1e8 --- /dev/null +++ b/molecule/default/tests/conftest.py @@ -0,0 +1,20 @@ +"""PyTest Fixtures.""" +from __future__ import absolute_import +import os +import pytest + + +def pytest_runtest_setup(item): + """Run tests only when under molecule with testinfra installed.""" + try: + import testinfra + except ImportError: + pytest.skip("Test requires testinfra", allow_module_level=True) + if "MOLECULE_INVENTORY_FILE" in os.environ: + pytest.testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( + os.environ["MOLECULE_INVENTORY_FILE"] + ).get_hosts("all") + else: + pytest.skip( + "Test should run only from inside molecule.", allow_module_level=True + ) diff --git a/molecule/default/tests/test_default.py b/molecule/default/tests/test_default.py new file mode 100644 index 0000000..516fa99 --- /dev/null +++ b/molecule/default/tests/test_default.py @@ -0,0 +1,35 @@ +"""Role testing files using testinfra.""" +import pytest +import requests + +def test_is_postgresql_runnnig_and_enabled(host): + nginx = host.service('nginx') + + assert nginx.is_running + assert nginx.is_enabled + +@pytest.mark.parametrize('path,content', ( +('static/static.html', b'static'), +('static/cache.js', b'static'), +('static/cache.css', b'static'), +('media/media.html', b'media') +)) +def test_statics_location_is_accessible(host, path, content): + response = requests.get(f'https://localhost:8080/{path}', + verify=False) + response.raise_for_status() + print(response.headers) + assert response.content == content + +@pytest.mark.parametrize('path,expiry', ( +('static/cache.js', 365*24*3600), +('static/cache.css', 365*24*3600), +)) +def test_js_and_css_files_are_cached(host, path, expiry): + response = requests.get(f'https://localhost:8080/{path}', verify=False) + assert f'max-age={expiry}' in response.headers['Cache-Control'] + +def test_upstream_is_accessible(host): + expected = b"Directory listing for /" + response = requests.get(f'https://localhost:8080/', verify=False) + assert expected in response.content diff --git a/tasks/catchall-vhost.yml b/tasks/catchall-vhost.yml new file mode 100644 index 0000000..9a92c34 --- /dev/null +++ b/tasks/catchall-vhost.yml @@ -0,0 +1,43 @@ +--- +- name: Create directory for selfsigned catch-all certificates + file: + name: "{{ nginx_catchall_ssl_directory }}" + state: directory + become: yes + tags: + - nginx + +- name: Generate private openssl key + openssl_privatekey: + path: "{{ nginx_catchall_privkey }}" + size: 2048 + become: yes + tags: + - nginx + +- name: Generate Certificate Signing Request (CSR) + openssl_csr: + path: "{{ nginx_catchall_csr }}" + privatekey_path: "{{ nginx_catchall_privkey }}" + common_name: selfsigned + become: yes + tags: + - nginx + +- name: Generate a Self Signed OpenSSL certificate + openssl_certificate: + path: "{{ nginx_catchall_fullchain }}" + privatekey_path: "{{ nginx_catchall_privkey }}" + csr_path: "{{ nginx_catchall_csr }}" + provider: selfsigned + become: yes + tags: + - nginx + +- name: Create the nginx catch-all + template: + src: "{{ nginx_catchall_template }}" + dest: "{{ nginx_vhost_path }}/{{ nginx_catchall_vhost_name }}" + become: yes + tags: + - nginx diff --git a/tasks/main.yml b/tasks/main.yml index bfb5fe4..11e40ae 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -2,33 +2,52 @@ # Variable setup. - name: Include OS-specific variables. include_vars: "{{ ansible_os_family }}.yml" + tags: + - nginx + - always - name: Define nginx_user. set_fact: nginx_user: "{{ __nginx_user }}" when: nginx_user is not defined - + tags: + - always # Setup/install tasks. - include_tasks: setup-RedHat.yml when: ansible_os_family == 'RedHat' + tags: + - always - include_tasks: setup-Ubuntu.yml when: ansible_distribution == 'Ubuntu' + tags: + - always - include_tasks: setup-Debian.yml when: ansible_os_family == 'Debian' + tags: + - always - include_tasks: setup-FreeBSD.yml when: ansible_os_family == 'FreeBSD' + tags: + - always - include_tasks: setup-OpenBSD.yml when: ansible_os_family == 'OpenBSD' + tags: + - always - include_tasks: setup-Archlinux.yml when: ansible_os_family == 'Archlinux' + tags: + - always # Vhost configuration. - import_tasks: vhosts.yml + tags: + - nginx + - nginx_vhost # Nginx setup. - name: Copy nginx configuration in place. diff --git a/tasks/vhosts.yml b/tasks/vhosts.yml index 7723ad5..81c181b 100644 --- a/tasks/vhosts.yml +++ b/tasks/vhosts.yml @@ -1,36 +1,42 @@ --- -- name: Remove default nginx vhost config file (if configured). +- name: Remove default nginx vhost config file (if configured) file: path: "{{ nginx_default_vhost_path }}" state: absent - when: nginx_remove_default_vhost | bool + when: + - nginx_remove_default_vhost | bool + - nginx_create_catchall_vhost | default(true) notify: restart nginx -- name: Ensure nginx_vhost_path exists. +- name: Ensure nginx_vhost_path exists file: path: "{{ nginx_vhost_path }}" state: directory notify: reload nginx -- name: Add managed vhost config files. +- include_tasks: catchall-vhost.yml + when: nginx_create_catchall_vhost | default(true) | bool + +- name: Add managed vhost config files template: - src: "{{ item.template|default(nginx_vhost_template) }}" - dest: "{{ nginx_vhost_path }}/{{ item.filename - | default(item.server_name.split(' ')[0] ~ '.conf') }}" + src: "{{ item.template }}" + dest: "{{ nginx_vhost_path }}/{{ item.filename }}" force: true owner: root group: "{{ root_group }}" + lstrip_blocks: yes + backup: yes mode: 0644 - when: item.state|default('present') != 'absent' + when: item.state | default('present') != 'absent' with_items: "{{ nginx_vhosts }}" notify: reload nginx tags: - skip_ansible_lint - -- name: Remove managed vhost config files. + - nginx_site_vhost + - nginx_vhost +- name: Remove managed vhost config files file: - path: "{{ nginx_vhost_path }}/{{ item.filename | - default(item.server_name.split(' ')[0] ~ '.conf') }}" + path: "{{ nginx_vhost_path }}/{{ item.filename }}.conf" state: absent when: item.state|default('present') == 'absent' with_items: "{{ nginx_vhosts }}" @@ -38,7 +44,7 @@ tags: - skip_ansible_lint -- name: Remove legacy vhosts.conf file. +- name: Remove legacy vhosts.conf file file: path: "{{ nginx_vhost_path }}/vhosts.conf" state: absent diff --git a/templates/cache-snippet.j2 b/templates/cache-snippet.j2 new file mode 100644 index 0000000..10065a5 --- /dev/null +++ b/templates/cache-snippet.j2 @@ -0,0 +1,6 @@ + +location {{ config.location }} { + alias {{ config.alias }}; + expires {{ config.expiries }}; + add_header Cache-Control "public, no-transform"; +} diff --git a/templates/default-catchall.j2 b/templates/default-catchall.j2 new file mode 100644 index 0000000..d629009 --- /dev/null +++ b/templates/default-catchall.j2 @@ -0,0 +1,8 @@ +server { + listen 80 default_server; + listen 443 ssl default_server; + server_name _; + ssl_certificate {{ nginx_catchall_fullchain }}; + ssl_certificate_key {{ nginx_catchall_privkey }}; + return 444; +} diff --git a/templates/django-vhost.j2 b/templates/django-vhost.j2 index 1dbf411..f1c997d 100644 --- a/templates/django-vhost.j2 +++ b/templates/django-vhost.j2 @@ -1,69 +1,64 @@ # {{ ansible_managed }} upstream {{ item.upstream.name }} { - server {{ item.upstream.server }} + server {{ item.upstream.server }}; } server { - listen 80; - {% if item.enable_https %} - listen 443 ssl {% if item.enable_http2 %}http2{% endif %}; - {% endif %} - server_name {% for server_name in item.server_names %}{{ server_name }} {% endfor %}; + listen 80; + {% if item.enable_https %} + listen 443 ssl {% if item.enable_http2 | default(false) %}http2{% endif %}; + {% endif %} + server_name {% for server_name in item.server_names %}{{ server_name }} {% endfor %}; - {% if item.access_log %} - access_log /var/log/nginx/{{ item.access_log }}.access.log; - {% endif %} + access_log /var/log/nginx/{{ item.access_log | default(item.filename) }}.access.log; + error_log /var/log/nginx/{{ item.error_log | default(item.filename) }}.error.log; - {% if item.error_log %} - error_log /var/log/nginx/{{ app_name }}.error.log; - {% endif %} + {% if item.enable_https | default(true) %} + if ($scheme = http) { + return 301 https://$host$request_uri; + } + {% endif %} - {% if item.enable_https %} - if ($scheme = http) { - return 301 https://$host$request_uri; - } - {% endif %} + ssl_certificate {{ item.certificate }}; + ssl_certificate_key {{ item.private_key }}; + ssl_trusted_certificate {{ item.certificate }}; - ssl_certificate {{ item.certificate }}; - ssl_certificate_key {{ item.private_key }}; - ssl_trusted_certificate {{ item.certificate }}; + {% if item.error_page is defined %} - {% if item.error_page is defined %} - error_page {{ item.error_page }}; - {% endif %} + error_page {{ item.error_page }}; - {% if item.static_root %} - location /static/ { - alias {{ item.static_root }}; - } - {% endif %} + {% endif %} - {% if item.media_root %} - location /media/ { - alias {{ item.media_root }}; - } - {% endif %} + {% if item.static_root %} + location /static/ { + alias {{ item.static_root }}; + } + {% endif %} - {% for location in item.additional_locations | default([]) %} - location {{ location.path }} { - alias {{ location.alias }}; - } - {% endfor %} + {% if item.media_root %} + location /media/ { + alias {{ item.media_root }}; + } + {% endif %} - {% if enable_default_cache %} - location ~* /static/.*\.(js|css)$ { - root {{ directories.project }}; - expires 2d; - add_header Cache-Control "public, no-transform"; - } - {% endif %} + {% for location in item.additional_locations | default([]) %} + location {{ location.path }} { + alias {{ location.alias }}; + } + {% endfor %} + {% for config in item.extra_snippets %} + {% filter indent(4) %} + {% include config.template %} + {% endfilter %} - location / { - proxy_pass {{ item.upstream }}; - proxy_set_header X-Forwarded-Host $server_name; - proxy_set_header Host $host; - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header X-Forwarded-Proto $scheme; - } - } + {% endfor %} + + location / { + proxy_pass http://{{ item.upstream.name }}; + proxy_set_header X-Forwarded-Host $server_name; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-Proto $scheme; + } +} diff --git a/templates/nginx.conf.j2 b/templates/nginx.conf.j2 index 7cdec60..5835aed 100644 --- a/templates/nginx.conf.j2 +++ b/templates/nginx.conf.j2 @@ -73,7 +73,7 @@ http { {% block http_includes %} include {{ nginx_conf_path }}/*.conf; {% if nginx_conf_path != nginx_vhost_path %} - include {{ nginx_vhost_path }}/*; + include {{ nginx_vhost_path }}/*.conf; {% endif %} {% endblock %} diff --git a/templates/staticpage-vhost.j2 b/templates/staticpage-vhost.j2 new file mode 100644 index 0000000..0fb6f0e --- /dev/null +++ b/templates/staticpage-vhost.j2 @@ -0,0 +1,34 @@ +# {{ansible_managed}} + +server { + listen 80; + server_name {% for server_name in item.server_names %}{{ server_name }} {% endfor %}; + + access_log /var/log/nginx/{{ item.access_log | default(item.filename) }}.access.log; + error_log /var/log/nginx/{{ item.error_log | default(item.filename) }}.error.log; + + root {{ item.root }}; + index index.html index.htm; + + {% if item.force_https | default(false) and item.enable_https | default(true) %} + return 301 https://$server_name$request_uri; + {% endif %} + +} + +{% if item.enable_https | default(true) %} +server { + listen 443 ssl; + server_name {% for server_name in item.server_names %}{{ server_name }} {% endfor %}; + + access_log /var/log/nginx/{{ item.access_log | default(item.filename) }}.access.log; + error_log /var/log/nginx/{{ item.error_log | default(item.filename) }}.error.log; + + ssl_certificate {{ item.certificate }}; + ssl_certificate_key {{ item.private_key }}; + + root {{ item.root }}; + index index.html index.htm; +} + +{% endif %}