Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Auto generate keys #2

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

MemberIT
Copy link

Add support auto generate private and public keys;
Fix permissions of wireguard config;
Update structure variables.

@adamruzicka
Copy link
Owner

Hi, thank you for you contribution. I briefly glanced over the code and it looks good to me, hopefully I'll have time to properly test it tomorrow. In the meantime, the tests failures seem to be related

wireguard_listen_port: 5888
wireguard_wg0_preshared_key: secret_preshared_key
wireguard_wg0_peer_settings: >
{% set _peers = {} -%}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't know one could do jinja templating within host/group vars files. Could you point me to docs where this is described?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not find a direct indication in the official documentation. But here is a link to changing variables using the filters https://docs.ansible.com/ansible/latest/user_guide/playbooks_variables.html#transforming-variables-with-jinja2-filters
and a links to the possibility of using a jean in the values ​​of variables:
https://groups.google.com/forum/m/#!topic/ansible-project/ZDz-8tcsdTA

Probably, I can transfer this part of the code to the template, but this can lead to loss of flexibility in the settings. In any case, I'll think about how to improve the code. If you have any suggestions, I will be glad to hear them.
P.S. Sorry for the delay in response, I was on vacation.
P.P.S. This PR is an attempt to combine the functionality of your role and this role https://github.com/mawalu/wireguard-private-networking

@MemberIT MemberIT changed the title Auto generate keys WIP: Auto generate keys Jan 16, 2019
Copy link
Owner

@adamruzicka adamruzicka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested the manage_keys: False route and left some comments inline


Each host needs to have `wireguard_networks` variable set. It should be a list of WireGuard interface name the host should use, by default it is an empty list. For each `$INTERFACE` specified here the host should have `wireguard_$INTERFACE_interface` and `wireguard_$INTERFACE_peers` vars set.
If `True` ansible automatically generated public and private pair keys. Default `False`.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/ansible automatically generated/will automatically generate/

shell: "umask 077; wg genkey | tee /etc/wireguard/privatekey_{{ item }} | wg pubkey > /etc/wireguard/publickey_{{ item }}"
when:
- not privatekey_{{ item }}.stat.exists
- wireguard_manage_keys
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to swap these two to have it work with wireguard_manage_keys: False

- name: Install linux headers (Ubuntu)
apt:
name:
- linux-headers-generic
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not an ubuntu guy, are headers-generic required if you install kernel flavor specific headers (linux-headers-{{ ansible_kernel }}

when: ansible_distribution == "Ubuntu"

- name: Install kernel headers (Debian)
apt:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fails on obscure devices with

fatal: [c2]: FAILED! => {"changed": false, "msg": "No package matching 'linux-headers-4.18.8-odroidc2' is available"}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants