diff --git a/meta/main.yml b/meta/main.yml index 6656480b74f7904ac29a047b7be2dbe7c292e6a9..cd123b8b06ad2bfbeb3c4c4c7e9ad7d083392be4 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -9,5 +9,8 @@ galaxy_info: - name: CentOS versions: - 7 + - name: Ubuntu + versions: + - jammy dependencies: - role: ics-ans-role-repository diff --git a/molecule/default/molecule.yml b/molecule/default/molecule.yml index aceca12953bf5bdfa4b2f7d9bf66c463d1cdefb6..711f698468c3f48c8cfbec88289d1bb1fb08b19a 100644 --- a/molecule/default/molecule.yml +++ b/molecule/default/molecule.yml @@ -17,6 +17,10 @@ provisioner: nginx_vhosts: - server_name: "ics-ans-role-nginx-default" root: "/var/www/test" + ics-ans-role-nginx-ubn: + nginx_vhosts: + - server_name: "ics-ans-role-nginx-ubn" + root: "/var/www/html" scenario: name: default verifier: @@ -36,3 +40,17 @@ platforms: command: /sbin/init groups: - molecule_group + - name: ics-ans-role-nginx-ubn + image: registry.esss.lu.se/ics-docker/ubuntu-systemd:22.04 + # SYS_ADMIN required to run systemctl + capabilities: + - SYS_ADMIN + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup + tmpfs: + - /run + - /tmp + command: /sbin/init + privileged: true + groups: + - molecule_group diff --git a/molecule/default/prepare.yml b/molecule/default/prepare.yml index 5358b3bd8c20d3c0ab64e4affc81469426b9f92e..7dfbdb2f67a3b46fb054938265c2596ff0f4d7c2 100644 --- a/molecule/default/prepare.yml +++ b/molecule/default/prepare.yml @@ -1,5 +1,14 @@ --- - name: Prepare hosts: all - gather_facts: false - tasks: [] + gather_facts: true + + roles: + - ics-ans-role-repository + + tasks: + - name: Ensure required packages are installed. + package: + name: + - 'curl' + state: present diff --git a/molecule/default/tests/test_default.py b/molecule/default/tests/test_default.py index d4c574bba3514143ad6a41728fb9f59bda070eac..86c9d251986b2bbc1d08fc70bc942e50fd04997f 100644 --- a/molecule/default/tests/test_default.py +++ b/molecule/default/tests/test_default.py @@ -7,7 +7,9 @@ testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( def test_directory_exists(host): - assert host.file("/var/www/test").exists + file1 = host.file("/var/www/test") + file2 = host.file("/var/www/html") + assert file1.exists or file2.exists def test_nginx_access(host): diff --git a/tasks/main.yml b/tasks/main.yml index c2d2a767bf08630a1f3426a6c8b296dc50e72ee2..5b8397544a74bf8c63bb8c30c51f211bd8f421b4 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,17 +1,18 @@ --- # Variable setup. - name: Include OS-specific variables. - include_vars: "{{ ansible_os_family }}.yml" + include_vars: "{{ ansible_os_family | lower }}.yml" - name: Define nginx_user. set_fact: nginx_user: "{{ __nginx_user }}" - when: nginx_user is not defined + when: nginx_user is not defined and ansible_os_family | lower == 'redhat' # Setup/install tasks. -- name: Ensure nginx is installed. +- name: Ensure required packages are installed. package: - name: "{{ nginx_package_name }}" + name: + - "{{ nginx_package_name }}" state: present # Vhost configuration. @@ -38,5 +39,5 @@ file: path: "{{ item.root }}" state: directory - owner: nginx + owner: "{{ nginx_owner }}" loop: "{{ nginx_vhosts }}" diff --git a/templates/nginx.conf.j2 b/templates/nginx.conf.j2 index 7cdec60283cbda86e3d8a17a831537fe4ee4fa88..702611202000700a64fddcb2d64858ea78b9e844 100644 --- a/templates/nginx.conf.j2 +++ b/templates/nginx.conf.j2 @@ -1,4 +1,6 @@ +{% if nginx_user is defined %} user {{ nginx_user }}; +{% endif %} error_log {{ nginx_error_log }}; pid {{ nginx_pidfile }}; diff --git a/vars/RedHat.yml b/vars/debian.yml similarity index 92% rename from vars/RedHat.yml rename to vars/debian.yml index 0138f8daabba7fb28b6a0cd873cf70582d7c8639..5d3cbbf547c135eb1daf59b13557e750285740f5 100644 --- a/vars/RedHat.yml +++ b/vars/debian.yml @@ -6,4 +6,4 @@ nginx_mime_file_path: /etc/nginx/mime.types nginx_pidfile: /var/run/nginx.pid nginx_vhost_path: /etc/nginx/conf.d nginx_default_vhost_path: /etc/nginx/conf.d/default.conf -__nginx_user: "nginx" +nginx_owner: root diff --git a/vars/redhat.yml b/vars/redhat.yml new file mode 100644 index 0000000000000000000000000000000000000000..e1b66d53ac5266eb104c07b6d2f6ce586ecfae32 --- /dev/null +++ b/vars/redhat.yml @@ -0,0 +1,10 @@ +--- +root_group: root +nginx_conf_path: /etc/nginx/conf.d +nginx_conf_file_path: /etc/nginx/nginx.conf +nginx_mime_file_path: /etc/nginx/mime.types +nginx_pidfile: /var/run/nginx.pid +nginx_vhost_path: /etc/nginx/conf.d +nginx_default_vhost_path: /etc/nginx/conf.d/default.conf +nginx_owner: "{{ __nginx_user }}" +__nginx_user: "nginx"