Ansible playbook used at https://codengine.io to configure tinc mesh VPN network , tested on Debian 9, Ubuntu 18.04 and Ubuntu 16.04
This sets up a tinc VPN between several servers. It also adds /etc/hosts entries for the inventory hostnames to resolve to the VPN IP addresses.
Your local machine (where Ansible is installed) must be able to log in to the remote servers as "root", preferably with passwordless public SSH key, which is specified as the remote_user in /ansible.cfg.
By default, this playbook will bind tinc to the IP address on the eth1 interface (private network interface on DigitalOcean Droplets). See the "Review Group Variables" section to change this.
Create a /hosts file with the nodes that you want to include in the VPN:
[vpn]
prod01 vpn_ip=10.0.0.1 ansible_host=162.243.125.98
prod02 vpn_ip=10.0.0.2 ansible_host=162.243.243.235
prod03 vpn_ip=10.0.0.3 ansible_host=162.243.249.86
prod04 vpn_ip=10.0.0.4 ansible_host=162.243.252.151
The first line, [vpn], specifies that the host entries directly below it are part of the "vpn" group. Members of this group will have the Tinc mesh VPN configured on them.
- The first column is where you set the inventory name of a host, "node01" in the first line of the example, how Ansible will refer to the host. This value is used to configure Tinc connections, and to generate
/etc/hostsentries. Do not use hyphens here, as Tinc does not support them in host names vpn_ipis the IP address that the node will use for the VPNansible_hostmust be set to a value that your ansible machine can reach the node at
Note: The inventory hostname, which we are using as each node's name in Tinc, can't contain characters that Tinc doesn't allow for node names. For example, hyphens (-) are not allowed.
The /roles/tinc/vars/main.yml file contains a few values that you may want to modify.
physical_ipspecifies which IP address you want tinc to bind to, based on network interface name. It is set toeth1(ansible_eth1) by default. On DigitalOcean,eth1is the private network interface so Private Networking must be enabled unless you would rather use the public network interface (eth0)vpn_interfacespecifies the tinc netname and vpn network interface. It's set tovpn0by default.vpn_netmaskspecifies the netmask that the will be applied to the VPN interface. By default, it's set to255.255.255.0, which means that eachvpn_ipis a Class C address which can only communicate with other hosts within the same subnet. For example, a10.0.0.xwill not be able to communicate with a10.0.1.xhost unless the subnet is enlarged by changingvpn_netmaskto something like255.255.0.0.
Run the playbook:
ansible-playbook site.ymlAfter the playbook completes, all of the hosts in the inventory file should be able to communicate with each other over the VPN network.
Log in to your first host and ping the second host:
ping 10.0.0.2Or, assuming one of your hosts is named prod02, run this:
ping prod02Feel free to test the other nodes.
All servers listed in the the [vpn] group in the /hosts file will be part of the VPN. To add new VPN members, simply add the new servers to the [vpn] group then re-run the Playbook:
ansible-playbook site.yml