Skip to content

Commit

Permalink
Consistency changes (#21)
Browse files Browse the repository at this point in the history
* Consistency changes
* Add support for Ubuntu 16.04

* Improved systemd service file

* Fix for vagrant test playbook

[ci skip]
  • Loading branch information
tersmitten committed Jan 10, 2017
1 parent d5fad72 commit f1cf173
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 19 deletions.
7 changes: 7 additions & 0 deletions Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ boxes = [
:cpu => "50",
:ram => "256"
},
{
:name => "ubuntu-1604",
:box => "bento/ubuntu-16.04",
:ip => '10.0.0.13',
:cpu => "50",
:ram => "256"
},
]

Vagrant.configure("2") do |config|
Expand Down
1 change: 1 addition & 0 deletions meta/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ galaxy_info:
versions:
- precise
- trusty
- xenial
galaxy_tags:
- system
- networking
Expand Down
35 changes: 19 additions & 16 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
dest: "{{ keepalived_checkout_path }}"
version: "{{ keepalived_version }}"
force: true
register: git_checkout
register: _git_checkout
tags:
- configuration
- keepalived
Expand All @@ -68,7 +68,7 @@
shell: aclocal && autoheader && automake --add-missing && autoreconf
args:
chdir: "{{ keepalived_checkout_path }}"
when: git_checkout | changed and keepalived_version | version_compare('v1.2.24', '>=')
when: _git_checkout | changed and keepalived_version | version_compare('v1.2.24', '>=')
tags:
- configuration
- keepalived
Expand All @@ -79,7 +79,7 @@
shell: ./configure {{ keepalived_configure_options | join(' ') }} && make -j{{ ansible_processor_cores + 1 }}
args:
chdir: "{{ keepalived_checkout_path }}"
when: git_checkout | changed
when: _git_checkout | changed
tags:
- configuration
- keepalived
Expand All @@ -101,7 +101,7 @@
shell: make install
args:
chdir: "{{ keepalived_checkout_path }}"
when: git_checkout | changed
when: _git_checkout | changed
notify: restart keepalived
tags:
- configuration
Expand All @@ -126,7 +126,7 @@
shell: git reset --hard && git clean -d -x -f
args:
chdir: "{{ keepalived_checkout_path }}"
when: git_checkout | changed
when: _git_checkout | changed
tags:
- configuration
- keepalived
Expand All @@ -136,7 +136,7 @@
- name: stat directories
stat:
path: "{{ item }}/"
register: stat_directories
register: _stat_directories
with_items:
- "{{ keepalived_configuration_file | dirname }}"
tags:
Expand All @@ -152,7 +152,7 @@
owner: root
group: root
mode: 0755
with_items: "{{ stat_directories.results }}"
with_items: "{{ _stat_directories.results }}"
when: item.stat.exists == false
tags:
- configuration
Expand Down Expand Up @@ -187,18 +187,21 @@
- keepalived
- keepalived-scripts

- name: create init script
template:
src: "{{ keepalived_init_script.lstrip('/') }}.j2"
dest: "{{ keepalived_init_script }}"
owner: root
group: root
mode: 0644
notify: restart keepalived
- include: service-upstart.yml
when: ansible_distribution_version | version_compare('15.04', '<')
tags:
- configuration
- keepalived
- keepalived-service
- keepalived-service-upstart

- include: service-systemd.yml
when: ansible_distribution_version | version_compare('15.04', '>=')
tags:
- configuration
- keepalived
- keepalived-service-init
- keepalived-service
- keepalived-service-systemd

- name: start and enable service
service:
Expand Down
19 changes: 19 additions & 0 deletions tasks/service-systemd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# tasks file for keepalived
---
- name: service | systemd | update script
template:
src: lib/systemd/system/keepalived.j2
dest: /lib/systemd/system/keepalived.service
owner: root
group: root
mode: 0644
register: _update_systemd_script
notify: restart keepalived
tags:
- keepalived-service-systemd-update

- name: service | systemd | reload
command: systemctl daemon-reload
when: _update_systemd_script | changed
tags:
- keepalived-service-systemd-reload
12 changes: 12 additions & 0 deletions tasks/service-upstart.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# tasks file for keepalived
---
- name: service | upstart | update script
template:
src: etc/init/keepalived.conf.j2
dest: /etc/init/keepalived.conf
owner: root
group: root
mode: 0644
notify: restart keepalived
tags:
- keepalived-service-upstart-update
18 changes: 18 additions & 0 deletions templates/lib/systemd/system/keepalived.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
; {{ ansible_managed }}

[Unit]
Description=Keepalived
After=network-online.target
Wants=network-online.target

[Service]
Type=simple
ExecStart=/usr/local/sbin/keepalived \
--dont-fork{% for option in keepalived_options %} --{{ option.name }}{% if option.value is defined %}={{ option.value }}{% endif %}{% endfor %} \

ExecReload=/bin/kill -HUP $MAINPID
KillMode=process
Restart=always

[Install]
WantedBy=multi-user.target
6 changes: 4 additions & 2 deletions tests/vagrant.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
roles:
- ../../
vars:
_keepalived_second_interface: "{{ hostvars[inventory_hostname]['ansible_' + (ansible_interfaces | difference(['lo', ansible_default_ipv4['interface']]) | sort | list | first)]['device'] }}"

keepalived_create_keepalived_script_user: true
# keepalived_global_defs_script_user: 'nobody nogroup'
keepalived_global_defs_script_user: keepalived_script
Expand Down Expand Up @@ -41,7 +43,7 @@

keepalived_vrrp_instances:
VI_1:
interface: eth1
interface: "{{ _keepalived_second_interface }}"
state: MASTER
priority: 101
virtual_router_id: 51
Expand All @@ -51,7 +53,7 @@
auth_pass: '4Apr3C*d'

virtual_ipaddresses:
- '10.0.0.10/24 dev eth1 label eth1:1'
- "10.0.0.10/24 dev {{ _keepalived_second_interface }} label {{ _keepalived_second_interface }}:1"

track_scripts:
- chk_sshd
Expand Down
1 change: 0 additions & 1 deletion vars/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,3 @@ keepalived_dependencies:
keepalived_checkout_path: /var/lib/ansible/keepalived/checkouts/keepalived

keepalived_configuration_file: /etc/keepalived/keepalived.conf
keepalived_init_script: /etc/init/keepalived.conf

0 comments on commit f1cf173

Please sign in to comment.