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

Add ability to download client configs #145

Open
srigi opened this issue Jan 31, 2022 · 3 comments
Open

Add ability to download client configs #145

srigi opened this issue Jan 31, 2022 · 3 comments
Labels
enhancement New feature or request

Comments

@srigi
Copy link

srigi commented Jan 31, 2022

Inspired by lablabs/ansible-collection-wireguard I would very welcome the ability to configure to download client configs for unmanaged peers.

@githubixx githubixx added the enhancement New feature or request label Feb 14, 2022
@githubixx
Copy link
Owner

I had something similar in mind but never had the time to implement it. I'll leave the issue open for now and mark it as enhancement.

@patsevanton
Copy link

Any news?

@patsevanton
Copy link

patsevanton commented May 9, 2022

This my playbook for install wireguard and generate client config.
Could you move something to role?

- hosts: wireguard
  become: true
  pre_tasks:
    - name: Install a qrencode, openresolv
      apt:
        pkg:
        - qrencode
        - openresolv
  roles:
    - githubixx.ansible_role_wireguard
  post_tasks:
    - name: Show wireguard__fact_public_key
      debug: var=wireguard__fact_public_key

    - name: Generate Wireguard client keypair
      shell: wg genkey | tee /etc/wireguard/client_privatekey | wg pubkey | tee /etc/wireguard/client_publickey
      args:
        creates: /etc/wireguard/client_privatekey
      become: yes

    - name: Register client private key
      shell: cat /etc/wireguard/client_privatekey
      register: client_privatekey
      changed_when: false
      become: yes

    - name: Register client public key
      shell: cat /etc/wireguard/client_publickey
      register: client_publickey
      changed_when: false
      become: yes

    - name: Add [Peer] to /etc/wireguard/wg0.conf
      lineinfile:
        dest: /etc/wireguard/wg0.conf
        line: "\n[Peer]"
        insertafter: EOF
      register: create_clients_configs

    - name: Add client publickey to /etc/wireguard/wg0.conf
      lineinfile:
        dest: /etc/wireguard/wg0.conf
        line: "PublicKey = {{ client_publickey.stdout }}"
        insertafter: EOF
      register: create_clients_configs

    - name: Add client AllowedIPs to /etc/wireguard/wg0.conf
      lineinfile:
        dest: /etc/wireguard/wg0.conf
        line: "AllowedIPs = 10.27.123.10/32"
        insertafter: EOF
      register: create_clients_configs

    - name: Create clients configs
      template:
        src: "clients.conf.j2"
        dest: "/etc/wireguard/client.conf"
        mode: 0644
      register: create_clients_configs

    - name: restart service wg-quick@wg0
      service:
        name: wg-quick@wg0
        state: restarted
      when: create_clients_configs.changed

    - name: Generate QR code
      shell: qrencode -t ansiutf8 < "/etc/wireguard/client.conf"
      changed_when: false
      register: qrcode

    - name: Show QR code
      debug:
        msg: "{{ qrcode.stdout_lines }}"

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

No branches or pull requests

3 participants