Skip to content

Commit

Permalink
Merge pull request #201 from tonyskapunk/ansible_plugins
Browse files Browse the repository at this point in the history
Add an option to enable plugins via ansible.
  • Loading branch information
tonyskapunk authored Feb 15, 2019
2 parents 5216732 + 75d3108 commit f47fbca
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ An ansible playbook could be used to install `recap` from a git repository. The
- `prefix` - The value of *PREFIX*, default: `/usr`.
- `tmp_install_dir` - The location where the cloned repo will be placed, default: `/tmp/recap`.
- `uninstall` - Then this is defined it will remove `recap`, default: *undefined*.
- `enable_plugins` - To enable the global plugin configuration default: `false`.
- `plugin_list` - A list of plugins to enable, from the `plugin-available` directory, default: `all`.

#### Install (default)

Expand All @@ -179,6 +181,23 @@ Install recap with *BINPATH* in `/bin`:

```
ansible-playbook tools/ansible_recap.yml -e binpath=/bin
```

Install recap with all plugins enabled:

```
ansible-playbook tools/ansible_recap.yml -e enable_plugins=true
```

Install recap with a list of plugins to enable:

```
ansible-playbook tools/ansible_recap.yml \
-e enable_plugins=true \
-e '{"plugin_list":[docker_top,redis]}'
```

#### Uninstall
Expand Down
40 changes: 40 additions & 0 deletions tools/ansible_recap.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
- git
- make
systemd_unit_dir: "{{ destdir }}/usr/lib/systemd/system"
enable_plugins: "no"
plugin_list:
- all
tasks:
- name: Set dependencies and timers
set_fact:
Expand Down Expand Up @@ -56,6 +59,43 @@
DESTDIR: "{{ destdir }}"
PREFIX: "{{ prefix }}"

- name: Enabling plugins
block:
- name: Finding all plugins available
block:
- name: Find all plugins
find:
paths: "{{ prefix }}/lib/recap/plugins-available"
register: plugins_found

- name: Create plugin list with all plugins found
set_fact:
plugin_list: "{{ plugin_list + [ item.path | basename ] }}"
with_items: "{{ plugins_found.files }}"
when: plugins_found.matched

- name: Remove "all" from list
set_fact:
plugin_list: "{{ plugin_list | difference(['all']) }}"

when: "'all' in plugin_list"

- name: enable plugins in global config
lineinfile:
path: /etc/recap.conf
insertafter: '#USEPLUGINS="no"'
line: 'USEPLUGINS="yes"'
state: present

- name: enable list of plugins
file:
dest: "{{ prefix }}/lib/recap/plugins-enabled/{{ item }}"
src: "{{ prefix }}/lib/recap/plugins-available/{{ item }}"
state: link
with_items: "{{ plugin_list }}"

when: enable_plugins

- name: Enable systemd timers
systemd:
name: "{{ item }}"
Expand Down

0 comments on commit f47fbca

Please sign in to comment.