Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
pdostal committed Jun 30, 2022
0 parents commit ce67bae
Show file tree
Hide file tree
Showing 7 changed files with 111 additions and 0 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/molecule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
name: Test deployment
'on':
pull_request:
push:
schedule:
# Run every Wednesday at 01:42
- cron: "42 1 * * 3"

jobs:
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- name: Check out codebase
uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.x'
- name: Install dependencies
run: pip3 install yamllint
- name: Lint repository
run: yamllint .
5 changes: 5 additions & 0 deletions handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
- name: Reconfigure the tunnel
ansible.builtin.service:
name: wg-quick@pdostal
state: restarted
14 changes: 14 additions & 0 deletions meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
galaxy_info:
role_name: wireguard
namespace: pdostal
author: Pavel Dostál
description: Configurable wireguard host
company: pdostal
license: license MIT
min_ansible_version: "2.9"
platforms:
- name: opensuse
galaxy_tags:
- wireguard
dependencies: []
19 changes: 19 additions & 0 deletions tasks/configure.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
- name: Generate configuration file
ansible.builtin.template:
src: wireguard.j2
dest: "/etc/wireguard/pdostal.conf"
owner: root
group: root
mode: '0700'
- name: Do not count this as a failure
ansible.builtin.command: "systemctl start wg-quick@pdostal"
ignore_errors: yes

Check warning on line 11 in tasks/configure.yml

View workflow job for this annotation

GitHub Actions / Lint

11:18 [truthy] truthy value should be one of [false, true]

Check warning on line 11 in tasks/configure.yml

View workflow job for this annotation

GitHub Actions / Lint

11:18 [truthy] truthy value should be one of [false, true]

Check warning on line 11 in tasks/configure.yml

View workflow job for this annotation

GitHub Actions / Lint

11:18 [truthy] truthy value should be one of [false, true]

Check warning on line 11 in tasks/configure.yml

View workflow job for this annotation

GitHub Actions / Lint

11:18 [truthy] truthy value should be one of [false, true]
- name: Do not count this as a failure1
ansible.builtin.command: "journalctl --no-tail -u wg-quick@pdostal"
register: journalctl
ignore_errors: yes

Check warning on line 15 in tasks/configure.yml

View workflow job for this annotation

GitHub Actions / Lint

15:18 [truthy] truthy value should be one of [false, true]

Check warning on line 15 in tasks/configure.yml

View workflow job for this annotation

GitHub Actions / Lint

15:18 [truthy] truthy value should be one of [false, true]

Check warning on line 15 in tasks/configure.yml

View workflow job for this annotation

GitHub Actions / Lint

15:18 [truthy] truthy value should be one of [false, true]

Check warning on line 15 in tasks/configure.yml

View workflow job for this annotation

GitHub Actions / Lint

15:18 [truthy] truthy value should be one of [false, true]
- name: journalctl
debug:
var: journalctl.stdout_lines
#notify: Reconfigure the tunnel

Check warning on line 19 in tasks/configure.yml

View workflow job for this annotation

GitHub Actions / Lint

19:4 [comments] missing starting space in comment

Check warning on line 19 in tasks/configure.yml

View workflow job for this annotation

GitHub Actions / Lint

19:3 [comments-indentation] comment not indented like content

Check warning on line 19 in tasks/configure.yml

View workflow job for this annotation

GitHub Actions / Lint

19:4 [comments] missing starting space in comment

Check warning on line 19 in tasks/configure.yml

View workflow job for this annotation

GitHub Actions / Lint

19:3 [comments-indentation] comment not indented like content

Check warning on line 19 in tasks/configure.yml

View workflow job for this annotation

GitHub Actions / Lint

19:4 [comments] missing starting space in comment

Check warning on line 19 in tasks/configure.yml

View workflow job for this annotation

GitHub Actions / Lint

19:3 [comments-indentation] comment not indented like content

Check warning on line 19 in tasks/configure.yml

View workflow job for this annotation

GitHub Actions / Lint

19:4 [comments] missing starting space in comment

Check warning on line 19 in tasks/configure.yml

View workflow job for this annotation

GitHub Actions / Lint

19:3 [comments-indentation] comment not indented like content
3 changes: 3 additions & 0 deletions tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
- ansible.builtin.import_tasks: prepare.yml
- ansible.builtin.import_tasks: configure.yml
27 changes: 27 additions & 0 deletions tasks/prepare.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
- name: Print some debug information
vars:
msg: |
Ansible Distribution: {{ ansible_distribution }}
Ansible Dist version: {{ ansible_distribution_version }}
Ansible OS family: {{ ansible_os_family }}
debug:
msg: "{{ msg.split('\n') }}"
- name: Install latest version on Archlinux
community.general.pacman:
name:
- wireguard-tools
state: present
when: ansible_distribution == 'Archlinux'

- name: Install latest version on Debian
ansible.builtin.apt:
name: wireguard
state: present
when: ansible_distribution == 'Debian'

- name: Install latest version on openSUSE
community.general.zypper:
name: wireguard-tools
state: present
when: ansible_os_family == "Suse"
19 changes: 19 additions & 0 deletions templates/wireguard.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[Interface]
Address = {{ address }}
ListenPort = 51871
PrivateKey = {{ private_key }}

{% for host in groups['all'] %}
{% if hostvars[host]['inventory_hostname'] != inventory_hostname %}
[Peer]
# {{ hostvars[host]['inventory_hostname'] }}
PublicKey = {{ hostvars[host]['public_key'] }}
AllowedIPs = {{ hostvars[host]['allowed_ips'] }}
{% if hostvars[host]['endpoint'] is defined %}
Endpoint = {{ hostvars[host]['endpoint'] }}
{% endif %}
PersistentKeepalive = 25

{% endif %}
{% endfor %}

0 comments on commit ce67bae

Please sign in to comment.