Skip to content

Commit

Permalink
Merge pull request #12 from p-rintz/gha
Browse files Browse the repository at this point in the history
 Github Actions tests of playbook
  • Loading branch information
wiggels authored Mar 15, 2023
2 parents 702e34e + 30f5bf3 commit c516bdb
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 0 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/ansible-playbook.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: ansible-role-snipe-it

on: [push, pull_request]

jobs:
test:
name: Test on python ${{ matrix.python_version }} and ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
python_version: ['3.9', '3.10', '3.11']
os: [ubuntu-22.04, ubuntu-20.04]


steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python_version }}
- name: Install dependencies
run: |
python3 -m pip install --upgrade pip
pip3 install ansible
printf '[defaults]\nroles_path=../' >ansible.cfg
- name: Install ansible-galaxy requirements
uses: nick-fields/retry@v2
with:
timeout_seconds: 180
max_attempts: 3
retry_on: error
command: ansible-galaxy install -r tests/requirements.yml
- name: Run playbook
run: |
ansible-playbook tests/test-gha.yml -i tests/inventory
10 changes: 10 additions & 0 deletions tasks/mysql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,32 +16,42 @@

- name: Delete anonymous user
community.mysql.mysql_user:
login_user: "{{ omit if lookup('ansible.builtin.env', 'GITHUB_ACTIONS') is not defined else 'root' }}"
login_password: "{{ omit if lookup('ansible.builtin.env', 'GITHUB_ACTIONS') is not defined else 'root' }}"
name: ""
host_all: true
state: absent
become: true

- name: Delete hostname-based root user
community.mysql.mysql_user:
login_user: "{{ omit if lookup('ansible.builtin.env', 'GITHUB_ACTIONS') is not defined else 'root' }}"
login_password: "{{ omit if lookup('ansible.builtin.env', 'GITHUB_ACTIONS') is not defined else 'root' }}"
name: root
host: "{{ ansible_nodename }}"
state: absent
become: true

- name: Remove test database
community.mysql.mysql_db:
login_user: "{{ omit if lookup('ansible.builtin.env', 'GITHUB_ACTIONS') is not defined else 'root' }}"
login_password: "{{ omit if lookup('ansible.builtin.env', 'GITHUB_ACTIONS') is not defined else 'root' }}"
name: test
state: absent
become: true

- name: Create snipeit database
community.mysql.mysql_db:
login_user: "{{ omit if lookup('ansible.builtin.env', 'GITHUB_ACTIONS') is not defined else 'root' }}"
login_password: "{{ omit if lookup('ansible.builtin.env', 'GITHUB_ACTIONS') is not defined else 'root' }}"
name: "{{ snipe_db_database }}"
state: present
become: true

- name: Create snipeit user
community.mysql.mysql_user:
login_user: "{{ omit if lookup('ansible.builtin.env', 'GITHUB_ACTIONS') is not defined else 'root' }}"
login_password: "{{ omit if lookup('ansible.builtin.env', 'GITHUB_ACTIONS') is not defined else 'root' }}"
name: "{{ snipe_db_username }}"
password: "{{ snipe_db_password }}"
priv: "{{ snipe_db_database }}.*:ALL"
Expand Down
2 changes: 2 additions & 0 deletions tests/requirements.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
collections:
- name: nginxinc.nginx_core
25 changes: 25 additions & 0 deletions tests/test-gha.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
- hosts: localhost
connection: local
remote_user: root
roles:
- ansible-role-snipe-it

tasks:
- name: Remove default vhost in nginx
ansible.builtin.file:
path: /etc/nginx/conf.d/default.conf
state: absent
become: true

- name: Make sure nginx service is restarted
ansible.builtin.systemd:
state: restarted
name: nginx
become: true

- name: Test reachability of /setup
ansible.builtin.uri:
url: "http://localhost/setup"
method: GET
register: _result
1 change: 1 addition & 0 deletions tests/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
remote_user: root
roles:
- snipeit

0 comments on commit c516bdb

Please sign in to comment.