Ansible module to create / update / delete Linode Nodebalancers
To enable this module to be read by Ansible you must place it in a 'library' folder and let ansible know where this is by editing your ansible.cfg - (docs)
Choose where you will save your custom ansible modules
mkdir ~/custom-ansible-modules
cd ~/custom-ansible-modules
Clone this repository
git clone [email protected]:DistilledLtd/ansible-linode-nodebalancer.git
Symlink the new module into the shared ansible folder
sudo mkdir -p /usr/share/ansible
sudo ln -s ~/custom-ansible-modules/ansible-linode-nodebalancer /usr/share/ansible/linode_nodebalancer
Add library to the defaults section of your ansible.cfg
[defaults]
library = /usr/share/ansible
This module makes use of the linode-python library. Since this is a local task (ie it runs on the machine triggering the playbook, rather than the remote servers) you will need to install this into (virtual) environment that is running the playbook.
pip install linode-python
- name: Setup Nodebalancer
sudo: false
run_once: true
local_action:
module: linode_nodebalancer
api_key: "{{ linode_api_key }}"
name: "My Nodebalancer"
- name: ensure http:80 config is present
sudo: false
run_once: true
local_action:
module: linode_nodebalancer_config
api_key: "{{ linode_api_key }}"
name: "My Nodebalancer"
port: 80
protocol: http
algorithm: roundrobin
NB, The node balancer will only work on private ip addresses (docs). On Ubuntu 14, with linode's network helper the private ip address is exposed as an ansible variable at 'ansible_eth0_1'. You can combine this with the current host name via 'inventory_hostname' to add a node for the current remote server.
- name: Ensure the current remote is a node on the node balancer
sudo: false
local_action:
module: linode_nodebalancer_node
api_key: "{{ linode_api_key }}"
name: "My Nodebalancer"
port: 80
protocol: http
node_name: "{{ inventory_hostname }}"
address: "{{hostvars[inventory_hostname]['ansible_eth0_1']['ipv4']['address']}}:80"
- Move repeating functions (e.g. `nodebalancer_find` and `handle_api_error`) into a file that can be imported.
- Allow https / SSH as a protocol
This code is provided under an MIT-style license. Please refer to the LICENSE file in the root of the project for specifics.