Skip to content

Commit

Permalink
Add possibility to install keepalived from repo (#49)
Browse files Browse the repository at this point in the history
* Add possibility to install keepalived from repo

default install mode is from git

* Fix https://github.com/Oefenweb/ansible-keepalived/pull/46/files#r753059604

* Fix https://github.com/Oefenweb/ansible-keepalived/pull/46/files#r753058074

* Add git specific tasks files

* Improve Install from repo

- Install before allow binding non-local IP (as need sysctl install by
procps)
- Install procps if need when keepalived_install_method == 'native'
- notify restart keepalived when upgrade keepalive and
keepalived_install_method == 'native'
- moved 'install dependencies' to git.yml
- add tags, apt_state (default is lastest), update_cache and
cache_valid_time on Install from repo

* Add possibility to install keepalived from repo

* Improved documentation

* Remove typo

Co-authored-by: Christian Iuga <[email protected]>
  • Loading branch information
tersmitten and Christian Iuga authored Nov 24, 2021
1 parent 3bc10c2 commit 2438623
Show file tree
Hide file tree
Showing 8 changed files with 149 additions and 129 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,17 @@ Set up the latest or a specific version of [Keepalived](http://www.keepalived.or
* `pkg-config` (will be installed)
* `libssl-dev` (will be installed)

when using `keepalived_install_method: native`

* `keepalived` (will be installed)
* `procps` (will be installed)

#### Variables

* `keepalived_git_repo`: [default: `https://github.com/acassen/keepalived.git`]: Keepalived git repo
* `keepalived_version`: [default: `v2.2.2`]: Keepalived version to install

* `keepalived_install_method`: [default `git`]: The way to install Keepalived (e.g. `native` (from Ubuntu repo), `git`)
* `keepalived_install`: [default: `[]`]: Additional packages to install (e.g. `['libnl-3-dev', 'libnl-genl-3-dev', 'libnl-route-3-dev', 'libnfnetlink-dev']`)
* `keepalived_configure_options`: [default: `[]`]: Options to pass to `./configure`

Expand Down
1 change: 1 addition & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# defaults file
---
keepalived_install_method: git
keepalived_git_repo: https://github.com/acassen/keepalived.git
keepalived_version: v2.2.2
keepalived_install: []
Expand Down
105 changes: 105 additions & 0 deletions tasks/git.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
# tasks file
---
- name: install | git | dependencies
apt:
name: "{{ keepalived_dependencies_git }}"
state: "{{ apt_install_state | default('latest') }}"
tags:
- keepalived-install-git-dependencies

- name: install | git | create (checkout) directory
file:
path: "{{ keepalived_checkout_path }}"
state: directory
owner: root
group: root
mode: 0755
tags:
- keepalived-install-git-checkout
- keepalived-install-git-checkout-directory

- name: install | git | checkout repository
git:
repo: "{{ keepalived_git_repo }}"
dest: "{{ keepalived_checkout_path }}"
version: "{{ keepalived_version }}"
force: true
register: _git_checkout
tags:
- keepalived-install-git-checkout-repository

- name: install | git | regenerate the build files
shell: >
aclocal && autoheader && automake --add-missing && autoreconf
args:
chdir: "{{ keepalived_checkout_path }}"
when:
- _git_checkout is changed
- keepalived_version is version('v1.2.24', '>=')
- keepalived_version is version('v2.1.0', '<')
tags:
- keepalived-install-git-build
- keepalived-install-git-build-regenerate-build-files

- name: install | git | regenerate the build files
shell: >
./build_setup
args:
chdir: "{{ keepalived_checkout_path }}"
when:
- _git_checkout is changed
- keepalived_version is version('v2.1.0', '>=')
tags:
- keepalived-install-git-build
- keepalived-install-git-build-regenerate-build-files

- name: install | git | build
shell: >
./configure {{ keepalived_configure_options | join(' ') }} && make -j{{ ansible_processor_cores + 1 }}
args:
chdir: "{{ keepalived_checkout_path }}"
when: _git_checkout is changed
tags:
- keepalived-install-git-build
- keepalived-install-git-build-configure-make

- name: install | git | remove (distro version)
apt:
name: keepalived
state: absent
purge: true
tags:
- keepalived-install-git-remove
- keepalived-install-git-remove-distro

- name: install | git | install
shell: >
make install
args:
chdir: "{{ keepalived_checkout_path }}"
when: _git_checkout is changed
notify: restart keepalived
tags:
- keepalived-install-git-install

- name: install | git | add script user
user:
name: keepalived_script
comment: 'keepalived script'
home: /nonexistent
shell: /bin/false
system: yes
when: keepalived_create_keepalived_script_user | bool
tags:
- keepalived-install-git-script
- keepalived-install-git-script-user

- name: install | git | cleanup build
shell: >
git reset --hard && git clean -d -x -f
args:
chdir: "{{ keepalived_checkout_path }}"
when: _git_checkout is changed
tags:
- keepalived-install-git-cleanup
- keepalived-install-git-cleanup-build
142 changes: 16 additions & 126 deletions tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,28 +1,34 @@
# tasks file
---
- name: install dependencies
- name: install additional
apt:
name: "{{ keepalived_dependencies }}"
name: "{{ keepalived_install }}"
state: "{{ apt_install_state | default('latest') }}"
update_cache: true
cache_valid_time: "{{ apt_update_cache_valid_time | default(3600) }}"
tags:
- configuration
- keepalived
- keepalived-install
- keepalived-install-dependencies
- keepalived-install-additional

- name: install additional
apt:
name: "{{ keepalived_install }}"
state: "{{ apt_install_state | default('latest') }}"
update_cache: true
cache_valid_time: "{{ apt_update_cache_valid_time | default(3600) }}"
- name: install | git
include: git.yml
when: keepalived_install_method == 'git'
tags:
- configuration
- keepalived
- keepalived-install
- keepalived-install-additional
- keepalived-install-git

- name: install | native
include: native.yml
when: keepalived_install_method == 'native'
tags:
- configuration
- keepalived
- keepalived-install
- keepalived-install-native

- name: allow binding non-local IP
sysctl:
Expand All @@ -36,122 +42,6 @@
- keepalived
- keepalived-ip-nonlocal-bind

- name: create (checkout) directory
file:
path: "{{ keepalived_checkout_path }}"
state: directory
owner: root
group: root
mode: 0755
tags:
- configuration
- keepalived
- keepalived-checkout
- keepalived-checkout-directory

- name: checkout repository
git:
repo: "{{ keepalived_git_repo }}"
dest: "{{ keepalived_checkout_path }}"
version: "{{ keepalived_version }}"
force: true
register: _git_checkout
tags:
- configuration
- keepalived
- keepalived-checkout
- keepalived-checkout-repository

- name: regenerate the build files
shell: >
aclocal && autoheader && automake --add-missing && autoreconf
args:
chdir: "{{ keepalived_checkout_path }}"
when:
- _git_checkout is changed
- keepalived_version is version('v1.2.24', '>=')
- keepalived_version is version('v2.1.0', '<')
tags:
- configuration
- keepalived
- keepalived-build
- keepalived-build-regenerate-build-files

- name: regenerate the build files
shell: >
./build_setup
args:
chdir: "{{ keepalived_checkout_path }}"
when:
- _git_checkout is changed
- keepalived_version is version('v2.1.0', '>=')
tags:
- configuration
- keepalived
- keepalived-build
- keepalived-build-regenerate-build-files

- name: build
shell: >
./configure {{ keepalived_configure_options | join(' ') }} && make -j{{ ansible_processor_cores + 1 }}
args:
chdir: "{{ keepalived_checkout_path }}"
when: _git_checkout is changed
tags:
- configuration
- keepalived
- keepalived-build
- keepalived-build-configure-make

- name: remove (distro version)
apt:
name: keepalived
state: absent
purge: true
tags:
- configuration
- keepalived
- keepalived-remove
- keepalived-remove-distro

- name: install
shell: >
make install
args:
chdir: "{{ keepalived_checkout_path }}"
when: _git_checkout is changed
notify: restart keepalived
tags:
- configuration
- keepalived
- keepalived-install

- name: add script user
user:
name: keepalived_script
comment: 'keepalived script'
home: /nonexistent
shell: /bin/false
system: yes
when: keepalived_create_keepalived_script_user | bool
tags:
- configuration
- keepalived
- keepalived-script
- keepalived-script-user

- name: cleanup build
shell: >
git reset --hard && git clean -d -x -f
args:
chdir: "{{ keepalived_checkout_path }}"
when: _git_checkout is changed
tags:
- configuration
- keepalived
- keepalived-cleanup
- keepalived-cleanup-build

- name: stat directories
stat:
path: "{{ item }}/"
Expand Down
9 changes: 9 additions & 0 deletions tasks/native.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# tasks file
---
- name: install | native | dependencies
apt:
name: "{{ keepalived_dependencies_native }}"
state: "{{ apt_install_state | default('latest') }}"
notify: restart keepalived
tags:
- keepalived-install-native-dependencies
2 changes: 1 addition & 1 deletion templates/etc/init/keepalived.conf.j2
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ respawn
script
exec start-stop-daemon \
--start \
--exec /usr/local/sbin/keepalived \
--exec {{ keepalived_install_prefix }}/keepalived \
-- --dont-fork{% for option in keepalived_options %} --{{ option.name }}{% if option.value is defined %}={{ option.value }}{% endif %}{% endfor %} \
end script
2 changes: 1 addition & 1 deletion templates/etc/systemd/system/keepalived.service.j2
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ 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 %}
ExecStart={{ keepalived_install_prefix }}/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
Expand Down
11 changes: 10 additions & 1 deletion vars/main.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
# vars file
---
keepalived_dependencies:
keepalived_dependencies_git:
- git
- build-essential
- automake
- libtool
- pkg-config
- libssl-dev
- procps
keepalived_dependencies_native:
- keepalived
- procps

keepalived_checkout_path: /var/lib/ansible/keepalived/checkouts/keepalived

keepalived_configuration_file: /etc/keepalived/keepalived.conf

keepalived_etc_systemd_file: /etc/systemd/system/keepalived.service
keepalived_etc_init_file: /etc/init/keepalived.conf
keepalived_install_prefix: >-
{%- if keepalived_install_method == 'git' -%}
/usr/local/sbin
{%- else -%}
/usr/sbin
{%- endif -%}

0 comments on commit 2438623

Please sign in to comment.