From c4e3a9e407a3418a3d320b011d8b772806e86711 Mon Sep 17 00:00:00 2001 From: Jannik Beyerstedt Date: Sat, 18 Jul 2020 23:41:21 +0200 Subject: [PATCH] [FIX] hostname should not have hyphens --- defaults/main.yml | 4 ++-- tasks/main.yml | 8 ++++---- templates/tinc-up.j2 | 2 +- templates/tinc.conf.j2 | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/defaults/main.yml b/defaults/main.yml index 8483868..e2c75df 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -1,10 +1,10 @@ --- # defaults file for tinc tinc_base_dir: /etc/tinc -tinc_tmp_pubkey: "tmp/rsa_key-{{ ansible_hostname }}.pub" +tinc_tmp_pubkey: "tmp/rsa_key-{{ ansible_hostname | replace('-', '_') }}.pub" # ID of the vpn to create tinc_vpn_id: vpn0 # hostname of the always-on server -tinc_central_host: hetzner-01 +tinc_central_host: hetzner_01 diff --git a/tasks/main.yml b/tasks/main.yml index 2e4476d..61115e4 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -38,14 +38,14 @@ become: yes fetch: src: "{{ tinc_base_dir }}/{{ tinc_vpn_id }}/rsa_key.pub" - dest: "{{ role_path }}/templates/tmp/rsa_key-{{ ansible_hostname }}.pub" + dest: "{{ role_path }}/templates/tmp/rsa_key-{{ ansible_hostname | replace('-', '_') }}.pub" flat: yes - name: Main - Create own hostfile become: yes template: src: "{{ role_path }}/templates/hostfile.j2" - dest: "{{ tinc_base_dir }}/{{ tinc_vpn_id }}/hosts/{{ ansible_hostname }}" + dest: "{{ tinc_base_dir }}/{{ tinc_vpn_id }}/hosts/{{ ansible_hostname | replace('-', '_') }}" - name: Main - Create tinc-up script become: yes @@ -64,8 +64,8 @@ - name: Main - Fetch all hostfiles become: yes fetch: - src: "{{ tinc_base_dir }}/{{ tinc_vpn_id }}/hosts/{{ ansible_hostname }}" - dest: "{{ role_path }}/files/tmp/{{ ansible_hostname }}" + src: "{{ tinc_base_dir }}/{{ tinc_vpn_id }}/hosts/{{ ansible_hostname | replace('-', '_') }}" + dest: "{{ role_path }}/files/tmp/{{ ansible_hostname | replace('-', '_') }}" flat: yes - name: "Main - Enable {{ tinc_vpn_id }}" diff --git a/templates/tinc-up.j2 b/templates/tinc-up.j2 index 29acac6..f60f10e 100644 --- a/templates/tinc-up.j2 +++ b/templates/tinc-up.j2 @@ -16,7 +16,7 @@ iptables -t nat -A POSTROUTING -o eth0 -s {{ tinc_vpn_net }} -j MASQUERADE {% elif ansible_os_family == 'Darwin' %} # only a single endpoint works, because tun interface is p2p -/sbin/ifconfig tun0 inet {{ tinc_client_ip | ipaddr('address') }} {{ tinc_remote_nets[0].gateway }} up netmast 255.255.255.0 +/sbin/ifconfig tun0 inet {{ tinc_client_ip | ipaddr('address') }} {{ tinc_remote_nets[0].gateway }} up netmask 255.255.255.0 /sbin/route -n add -net {{ tinc_remote_nets[0].net_cidr }} {{ tinc_remote_nets[0].gateway }} diff --git a/templates/tinc.conf.j2 b/templates/tinc.conf.j2 index da2c297..dce748a 100644 --- a/templates/tinc.conf.j2 +++ b/templates/tinc.conf.j2 @@ -1,8 +1,8 @@ -Name = {{ ansible_hostname }} +Name = {{ ansible_hostname | replace('-', '_') }} {% if (override_os_family is defined) | ternary(override_os_family,ansible_os_family) != 'Darwin' %} Device = /dev/net/tun {% endif %} -{% if ansible_hostname != tinc_central_host %} +{% if ansible_hostname | replace('-', '_') != tinc_central_host %} ConnectTo = {{ tinc_central_host }} {% endif %} AddressFamily = any