Page cover

Ansible WireGuard workflow on Linode

Spinning up a VPS on Linode with your favourite Linux distro and setting up a WireGuard server is truly easy and intuitive on its WebUI portal. I have done the same process of a VPS setup and its required configuration so many times on all those different cloud providers like Digital Ocean and Vultr. They are almost the same in user experience on each portal. However, I can't use it all platforms at the same time to make my workflow template-able like any other things in life. Repeating the same damn things is a bit boring and tedious. I am not a big fan of repeating the same thing again and again as I am lazy enough to get bored easily. Thus always looking for the easier way to make my life less miserable. Plus the cloud is not supposed to consume like that. It has its own way; DevOps way of life. So I have invested a week worth of research and implementing Ansible playbooks to automate my workflow on Linode.

In this article, I would like to share the Ansible workflow I use on Linode. Here is the list of prerequisites before straight delve into the tutorial.

  • A valid Linode Personal Access Token (API Token)

  • Python version 2.7 or higher installed

  python --version
  • The official Python library for the Linode API v4

  sudo apt-get install python-pip
  sudo pip install linode_api4
  • Ansible's 2.8 release

  • Git

  • Basic understanding of Ansible ad-hoc and playbooks concept

Setting up Ansible Playbooks

 ansible-vault encrypt_string 'PlainTextPassword' --name 'password'

Sample output as below

  • Copy the encrypted password block into var/linode_wg.yml

  • Repeat the same encryption process with Linode API token

  • As you are in var/linode_wg.yml, update the following variables as desired.

  • Also note that wg_ip: variable's IP subnet needs to be same as the subnet used in wg/users.csv as shown in below sample.

  • Make sure that ansible.cfg is configured correctly to work with Ansible playbooks.

  • Prepare the Jinja2 templates as following.

Prepare and Execute Ansible Playbooks

  • Believe it or not. It is all good and ready to run wg_build.yml playbook now.

  • Relevant notes are added to each playbook for further description as well.

  • To tear down the Linode, run playbooks/wg_PURGE.yml as below.

Now you see how easy it is to build and tear down WireGuard VPN server Linode with one Ansible command in DevOpsy fashion. Hope it's helpful and informative.

Last updated

Was this helpful?