Skip to content

Commit

Permalink
DO NOT MERGE
Browse files Browse the repository at this point in the history
I'm doing some crazy stuff here.
  • Loading branch information
grisu48 committed Jul 16, 2024
1 parent 5afa1f5 commit 44a6773
Show file tree
Hide file tree
Showing 19 changed files with 48 additions and 89 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,11 @@ jobs:
with:
python-version: '3.11'
- name: Install requirements
run: sudo apt-get install docker python3-pip
run: sudo apt-get install ansible podman python3-pip
- name: Install ansible collections
run: ansible-galaxy collection install community.general
- name: Install molecule
# https://www.jeffgeerling.com/blog/2024/newer-versions-ansible-dont-work-rhel-8[]
run: "pip3 install 'ansible-core<2.17' molecule molecule-plugins[docker] pytest testinfra"
run: "pip3 install molecule molecule-plugins[podman]"
- name: Run Molecule
run: molecule test
env:
Expand Down
10 changes: 10 additions & 0 deletions files/www/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!doctype html>
<html>
<head>
<title>nginx</title>
</head>
<body>
<h1>Default page for nginx</h1>
<p>Congratulations! Your nginx role has been successfully installed on this server</p>
</body>
</html>
3 changes: 0 additions & 3 deletions meta/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ galaxy_info:
versions:
- 15.5
- 15.6
- name: debian
versions:
- bullseye

galaxy_tags:
- nginx
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FROM registry.opensuse.org/opensuse/leap:15.5

# Install systemd and development tools, clear cache
RUN zypper in -y systemd systemd-sysvinit firewalld python3 python3-firewall curl && rm -rf /var/cache/*
RUN zypper in -y systemd systemd-sysvinit python311 curl && rm -rf /var/cache/*

# Start container with systemd
ENTRYPOINT ["/usr/sbin/init"]
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FROM registry.opensuse.org/opensuse/leap:15.6

# Install systemd and development tools, clear cache
RUN zypper in -y systemd systemd-sysvinit firewalld python3 python3-firewall curl && rm -rf /var/cache/*
RUN zypper in -y systemd systemd-sysvinit firewalld python311 curl && rm -rf /var/cache/*

# Start container with systemd
ENTRYPOINT ["/usr/sbin/init"]
42 changes: 11 additions & 31 deletions molecule/default/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,56 +2,36 @@
dependency:
name: galaxy
driver:
name: docker
name: podman
platforms:
- name: leap15_5
image: registry.opensuse.org/opensuse/leap:15.5
dockerfile: Dockerfile.leap15_5
dockerfile: Containerfile.leap15_5
command: ${MOLECULE_DOCKER_COMMAND:-"/usr/sbin/init"}
privileged: true
cgroupns: host
systemd: true
tmpfs:
- /run
- /tmp
"/tmp": "exec"
"/run": "rw,noexec,nosuid,nodev"
- name: leap15_6
image: registry.opensuse.org/opensuse/leap:15.6
dockerfile: Dockerfile.leap15_6
dockerfile: Containerfile.leap15_6
command: ${MOLECULE_DOCKER_COMMAND:-"/usr/sbin/init"}
privileged: true
cgroupns: host
systemd: true
tmpfs:
- /run
- /tmp
- name: bullseye
image: docker.io/debian:bullseye
dockerfile: Dockerfile.bullseye
command: ${MOLECULE_DOCKER_COMMAND:-"/sbin/init"}
privileged: true
cgroupns: host
tmpfs:
- /run
- /tmp
- name: bookworm
image: docker.io/debian:bookworm
dockerfile: Dockerfile.bookworm
command: ${MOLECULE_DOCKER_COMMAND:-"/sbin/init"}
privileged: true
cgroupns: host
tmpfs:
- /run
- /tmp
"/tmp": "exec"
"/run": "rw,noexec,nosuid,nodev"
provisioner:
name: ansible
inventory:
host_vars:
leap15_5:
vhosts_dir: "/etc/nginx/vhosts.d"
deploy_nginx_config: true
ansible_python_interpreter: "/usr/bin/python3"
ansible_python_interpreter: "/usr/bin/python3.11"
leap15_6:
vhosts_dir: "/etc/nginx/vhosts.d"
deploy_nginx_config: true
ansible_python_interpreter: "/usr/bin/python3"
ansible_python_interpreter: "/usr/bin/python3.11"
bullseye:
vhosts_dir: "/etc/nginx/sites-enabled"
deploy_nginx_config: false
Expand Down
2 changes: 1 addition & 1 deletion molecule/default/tests/test_default.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all')

def test_phpinfo(host):
def test_index(host):
cmd = host.run("curl -v http://127.0.0.1/index.html")
print(cmd.stdout)
assert 'HTTP/1.1 200 OK' in cmd.stderr
Expand Down
26 changes: 10 additions & 16 deletions tasks/default-page.yml
Original file line number Diff line number Diff line change
@@ -1,27 +1,21 @@
---
# setup a default page
# setup default page

- name: Ensure default page directory exists
file:
path: /srv/www/default
- name: Ensure default template exists
copy:
src: www/
dest: "{{www_dir}}/default/"
owner: "{{nginx_user}}"
group: "{{nginx_group}}"
mode: 0755
state: directory
tags: ['nginx']
- name: Ensure default page exists
template:
src: index.j2
dest: "{{www_dir}}/default/index.html"
owner: "{{nginx_user}}"
group: "{{nginx_group}}"
mode: 0755
mode: 0644
directory_mode: 0755
force: false
tags: ['nginx']

- name: Ensure default page nginx template exists
template:
src: default-www.j2
dest: "{{vhosts_dir}}/default-www.conf"
src: default.j2
dest: "{{vhosts_dir}}/default.conf"
owner: root
group: root
mode: 0644
Expand Down
5 changes: 4 additions & 1 deletion tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@

# Distribution specific vars are ALWAYS needed, so don't forget the tags here
- name: include distribution specific vars
include_vars: "{{ansible_distribution}}_{{ansible_distribution_version}}.yml"
include_vars: "{{ansible_distribution}}.yml"
tags: ['nginx', 'firewall', 'systemd']

- include_tasks: software.yml
tags: ['nginx', 'firewall', 'systemd']
- include_tasks: firewall.yml
when: config_firewall == true
tags: ['firewall']
- include_tasks: default-page.yml
when: setup_default_page == true
tags: ['nginx']
1 change: 1 addition & 0 deletions tasks/software.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
name: "{{ packages }}"
state: present
tags: ['nginx']

- name: Ensure nginx service is enabled
systemd:
name: "{{ nginx_service }}"
Expand Down
2 changes: 1 addition & 1 deletion templates/default-www.j2 → templates/default.j2
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ server {
listen [::]:80;

root /srv/www/default;
index index.php index.html index.htm;
index index.html index.htm;

server_name {{default_page_hostname}};

Expand Down
13 changes: 0 additions & 13 deletions templates/index.j2

This file was deleted.

File renamed without changes.
1 change: 0 additions & 1 deletion vars/Debian_11.10.yml

This file was deleted.

2 changes: 1 addition & 1 deletion vars/main.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
# vars file for lemp
# vars file for nginx
5 changes: 3 additions & 2 deletions vars/openSUSE Leap_15.6.yml → vars/openSUSE Leap.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
---
# openSUSE Leap 15.6 specific variables
# openSUSE Leap specific variables

## Software packages

packages: ['nginx']
packages:
- nginx
nginx_service: "nginx"

## OS-Specific directories
Expand Down
14 changes: 0 additions & 14 deletions vars/openSUSE Leap_15.5.yml

This file was deleted.

0 comments on commit 44a6773

Please sign in to comment.