Skip to content

WIP: Auto generate keys#2

Open
MemberIT wants to merge 5 commits into
adamruzicka:masterfrom
sportsru:auto_generate_keys
Open

WIP: Auto generate keys#2
MemberIT wants to merge 5 commits into
adamruzicka:masterfrom
sportsru:auto_generate_keys

Conversation

@MemberIT
Copy link
Copy Markdown

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

@adamruzicka
Copy link
Copy Markdown
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

Comment thread README.md
wireguard_listen_port: 5888
wireguard_wg0_preshared_key: secret_preshared_key
wireguard_wg0_peer_settings: >
{% set _peers = {} -%}
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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

Comment thread README.md
### `wireguard_manage_keys`

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
Copy Markdown
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
Copy Markdown
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

Comment thread tasks/debian_packages.yml
- name: Install linux headers (Ubuntu)
apt:
name:
- linux-headers-generic
Copy link
Copy Markdown
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 }}

Comment thread tasks/debian_packages.yml
when: ansible_distribution == "Ubuntu"

- name: Install kernel headers (Debian)
apt:
Copy link
Copy Markdown
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