Skip to content
Snippets Groups Projects
Commit 40dcfb1e authored by nimrod's avatar nimrod
Browse files

First commit, a big dump.

parents
No related branches found
No related tags found
No related merge requests found
Role Name
=========
A brief description of the role goes here.
Requirements
------------
Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required.
Role Variables
--------------
::
consul_endpoint: # Endpoint (propably a load-balancer) to join the cluster,
# if not defined then working in a single-node cluster.
consul_cluster_size: 3 # Number of nodes in the cluster, unless an endpoint
# is not defined, then the cluster size is 1.
consul_mode: agent # Consul mode, either server or agent. If an endpoint is
# not defined, defaults to server.
The logic is: if the endpoint is defined then act according to the mode and join
the cluster at the endpoint. If the endpoint is not defined then it's a single
server cluster (probably a dev/ staging environment).
A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well.
Dependencies
------------
A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles.
Example Playbook
----------------
Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too:
- hosts: servers
roles:
- { role: username.rolename, x: 42 }
License
-------
MIT
Author Information
------------------
An optional section for the role authors to include contact information, or a website (HTML is not allowed).
To do
-----
- Move config to /etc/default/consul.
- Handle Upstart and SystemD (maybe sysV also).
- webui (https://consul.io/intro/getting-started/ui.html).
- Test variables order of evaluation (maybe setting variables outside of the
role doesn't take effect as expected).
- Set versions as vars (easier upgrade path).
- Metrics.
---
# defaults file for ansible-consul
consul_endpoint:
consul_mode: '{{ "agent" if consul_endpoint is defined else "server" }}'
consul_cluster_size: '{{ 3 if consul_endpoint is defined else 1 }}'
---
# handlers file for ansible-consul
- name: Reload Upstart
command: /sbin/initctl reload-configuration
- name: Reload SystemD
command: /bin/systemctl daemon-reload
- name: Restart Consul
service:
name: consul
state: restarted
- name: Join Consul cluster
command: "/usr/local/bin/consul join {{ consul_lb }}"
when: consul_lb is defined
---
galaxy_info:
author: your name
description:
company: your company (optional)
# If the issue tracker for your role is not on github, uncomment the
# next line and provide a value
# issue_tracker_url: http://example.com/issue/tracker
# Some suggested licenses:
# - BSD (default)
# - MIT
# - GPLv2
# - GPLv3
# - Apache
# - CC-BY
license: license (GPLv2, CC-BY, etc)
min_ansible_version: 1.2
#
# Below are all platforms currently available. Just uncomment
# the ones that apply to your role. If you don't see your
# platform on this list, let us know and we'll get it added!
#
#platforms:
#- name: EL
# versions:
# - all
# - 5
# - 6
# - 7
#- name: GenericUNIX
# versions:
# - all
# - any
#- name: Fedora
# versions:
# - all
# - 16
# - 17
# - 18
# - 19
# - 20
# - 21
# - 22
#- name: Windows
# versions:
# - all
# - 2012R2
#- name: SmartOS
# versions:
# - all
# - any
#- name: opensuse
# versions:
# - all
# - 12.1
# - 12.2
# - 12.3
# - 13.1
# - 13.2
#- name: Amazon
# versions:
# - all
# - 2013.03
# - 2013.09
#- name: GenericBSD
# versions:
# - all
# - any
#- name: FreeBSD
# versions:
# - all
# - 8.0
# - 8.1
# - 8.2
# - 8.3
# - 8.4
# - 9.0
# - 9.1
# - 9.1
# - 9.2
#- name: Ubuntu
# versions:
# - all
# - lucid
# - maverick
# - natty
# - oneiric
# - precise
# - quantal
# - raring
# - saucy
# - trusty
# - utopic
# - vivid
#- name: SLES
# versions:
# - all
# - 10SP3
# - 10SP4
# - 11
# - 11SP1
# - 11SP2
# - 11SP3
#- name: GenericLinux
# versions:
# - all
# - any
#- name: Debian
# versions:
# - all
# - etch
# - jessie
# - lenny
# - squeeze
# - wheezy
#
# Below are all categories currently available. Just as with
# the platforms above, uncomment those that apply to your role.
#
#categories:
#- cloud
#- cloud:ec2
#- cloud:gce
#- cloud:rax
#- clustering
#- database
#- database:nosql
#- database:sql
#- development
#- monitoring
#- networking
#- packaging
#- system
#- web
dependencies: []
# - role: StatsD
# tags: StatsD
# - role: Exim
# tags: Exim
# when: ansible_os_family == 'Debian'
---
# tasks file for ansible-consul
- name: apt install prerequisites
apt:
name: unzip
state: present
update_cache: yes
cache_valid_time: 3600
- name: Create user
user:
name: consul
createhome: yes
home: /var/lib/consul
shell: /bin/false
system: yes
state: present
- name: Add email alias
lineinfile:
dest: /etc/aliases
line: 'consul: root'
regexp: '^consul:'
create: yes
- name: Create configuration directory
file:
path: /etc/consul.d
owner: root
group: root
mode: '0755'
state: directory
- name: Get tarball
register: get_consul
get_url:
url: https://dl.bintray.com/mitchellh/consul/0.5.2_linux_amd64.zip
dest: /root/consul.zip
owner: root
group: root
mode: '0644'
- name: Unpack tarball
when: get_consul.changed
notify:
- Restart Consul
unarchive:
copy: no
dest: /usr/local/bin
group: root
owner: root
mode: '0755'
src: /root/consul.zip
- name: Get python-consul
pip:
name: python-consul
state: present
- name: Add configuration
template:
src: '{{ item.src }}'
dest: '{{ item.dest }}'
owner: root
group: root
mode: '0644'
with_items:
- src: consul.conf.j2
dest: /etc/init/consul.conf
- src: consul.json.j2
dest: /etc/consul.d/consul.json
notify:
- Restart Consul
- Join Consul cluster
- name: Start Consul
service:
name: consul
state: started
- name: Get Consul Template tarball
register: get_consul_template
get_url:
url: https://github.com/hashicorp/consul-template/releases/download/v0.10.0/consul-template_0.10.0_linux_amd64.tar.gz
dest: /root/consul-template.tar.gz
owner: root
group: root
mode: '0644'
- name: Unpack Consul Template tarball
when: get_consul_template.changed
register: consul_template_unarchive
unarchive:
copy: no
dest: /root
group: root
owner: root
src: /root/consul-template.tar.gz
- name: Copy Consul template binary
when: consul_template_unarchive.changed|default('false')
command: cp /root/consul-template_0.10.0_linux_amd64/consul-template /usr/local/bin
limit nofile 5000 10000
env GOMAXPROCS=5
author "Nimrod Adar <nimrod.adar@wiser.com>"
description "Consul"
start on runlevel [2345]
stop on runlevel [!2345]
setgid consul
setuid consul
limit nofile 5000 10000
respawn
respawn limit 10 10
env GOMAXPROCS=5
exec /usr/local/bin/consul agent -config-dir /etc/consul.d
{{ consul_config | to_nice_json }}
---
# vars file for ansible-consul
consul_config:
enable_syslog: True
data_dir: /var/lib/consul
datacenter: '{{ ec2_region|default(omit) }}'
start_join: '{{ consul_endpoint|default(omit) }}'
server: '{{ consul_mode == "server" }}'
bootstrap_expect: '{{ consul_cluster_size if consul_mode == "server" else omit }}'
bind_addr: '{{ ansible_default_ipv4.address if consul_mode == "server" else omit }}'
#statsd_addr: "127.0.0.1"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment