Role: HAProxy in HA with Keepalived in Ubuntu

https://github.com/rcastells/ansible

This role is created to work with:

  • 2 LoadBalancers
  • 1 or more WebServers

First of all review your inventory file and create a group for loadbalancers and another one for webservers:

[loadbalancers]
 ha01 ansible_host=ec2-52-50-164-246.eu-west-1.compute.amazonaws.com
 ha02 ansible_host=ec2-52-48-101-228.eu-west-1.compute.amazonaws.com

[webservers]
 web01 ansible_host=ec2-52-50-143-215.eu-west-1.compute.amazonaws.com
 web02 ansible_host=ec2-52-31-14-253.eu-west-1.compute.amazonaws.com

Then, take a look at host_vars directory and inside the role at default vars:

host_vars

You must define for ha01 and ha02 which one will be the master and the VIP between servers:

keepalived_interval: 2
keepalived_debug: 2
keepalived_interface: eth0
keepalived_MASTER_SLAVE: MASTER (or SLAVE)
keepalived_priority: 101 (or 100)
keepalived_virtualip: 172.31.39.157 (your VIP)

default vars

You could need to change these vars.

---
# Set default haproxy installation package if not defined at host_vars
haproxy_url: http://www.haproxy.org/download/1.6/src/haproxy-1.6.7.tar.gz
haproxy_version: 1.6.7

Finally take a look at the initial playbook (haproxy-ha.yml):

---
# HAProxy servers
- hosts: webservers
become: yes

- hosts: loadbalancers
become: yes
roles:
- haproxy-ha

We want to connect to webservers just to gather their facts and then use them in haproxy.cfg template file.

To run the playbook you must run:

ansible-playbook -i <inventory_file>  haproxy-ha.yml -k -K -u <username>

As an example if you have ssh key connection to all servers you could run:

ansible-playbook -i inventory/production haproxy-ha.yml

 

Advertisements

Role: Android-SDK for Linux, Win and Mac

This role allows you to install Android-SDK for Linux, Windows or Mac:

https://github.com/rcastells/ansible/tree/master/roles/androidsdk

Ubuntu OS

In order to run the playbook for Ubuntu OS you must have a user with SSH access to the server and sudo privileges to become root.

Edit your inventory file and add ubuntu server alias if necessary:

ubuntu ansible_host=<ubuntu_host>

Create your playbook file (for example androidsdk.yml) and add the ubuntu hosts:

--- 
# Playbook that installs AndroidSDK 
- hosts: ubuntu
    roles:
     - androidsdk

Then run the playbook as follows:

ansible-playbook -i <your_inventory> androidsdk.yml -u <user> -b -K -k

Notes:
‘-k’ it will ask you for your password. You can avoid it if you are going to use ssh keys.
‘-u <user>’ is the user you are going to use to connect to remote server. You can avoid it if you are going to use your current username.
‘-b’ is to become root on the remote server. Mandatory.
‘-K’ it will ask you for sudo password. Mandatory if you need password to become root.

As you will see the playbook shows the list of available packages and by default it will install 1,2,3,5,37.

You can change which packages do you want to install by editing file roles/androidsdk/defaults/main.yml variable:

android_tools_filter: "1,2,3,5,37"

Also you could edit a variable for every host, so you can specify different packages for every host or group of hosts.

WindowsOS

In order to run the playbook for WindowsOS you must have credentials for an Admin account.

Edit your inventory file and add ubuntu server alias if necessary:

windows ansible_host=<windows_host>

Edit or create the playbook file androidsdk.yml file and put windows host alias in host option as follows:

--- 
# Playbook that installs AndroidSDK + JAVA
- hosts: windows
     roles:
        - androidsdk

 

Ansible will use winrm connection. In order to be able to run the Ansible on the remote host you must run ConfigureRemotingForAnsible.ps1 file on the WindowsOS remote host. So connect to your windows host first and run the powershell script. You must be able also to connect to winrmi secure port (by default 5986).
Create or edit host_vars file for this windows host (not included in github) and put your Admin account credentials in host_vars/windows.yml file as follows (here you can also change wirmi port if necessary):

ansible_user: Administrator
ansible_password: "password_example"
ansible_port: 5986
ansible_connection: winrm
ansible_winrm_server_cert_validation: ignore

Remember to run the Powershell script ConfigureRemotingForAnsible.ps1 on remote host before to run the playbook.

Then run the playbook as follows:

ansible-playbook -i <your_inventory> androidsdk.yml

MacOS

In order to run the playbook for MacOSX you must have a user with SSH access to the server and sudo privileges to become root.

Edit your inventory file and add mac server alias if necessary:

mac ansible_host=<mac_host>

Edit or create androidsdk.yml file and put mac host alias in host option as follows:

--- 
# Playbook that installs AndroidSDK + JAVA
- hosts: mac
   roles:
     - androidsdk

Then run the playbook as follows:

ansible-playbook -i inventory/production androidsdk.yml -u <user> -b -K -k

Notes:
‘-k’ it will ask you for your password. You can avoid it if you are going to use ssh keys.
‘-u <user>’ is the user you are going to use to connect to remote server. You can avoid it if you are going to use your current username.
‘-b’ is to become root on the remote server. Mandatory.
‘-K’ it will ask you for sudo password. Mandatory if you need the password to become root.

You can change which packages do you want to install by editing file roles/androidsdk/defaults/main.yml variable:

android_tools_filter: "1,2,3,5,37"

Also you could edit a variable for every host, so you can specify different packages for every host or group of hosts.