Skip to content

Commit

Permalink
Merge pull request #17 from codecounselor/master
Browse files Browse the repository at this point in the history
Made role idempotent
  • Loading branch information
rossmcdonald authored Nov 7, 2016
2 parents 7eed358 + 74a0661 commit 1024bf4
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 27 deletions.
16 changes: 14 additions & 2 deletions handlers/main.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
---
# The order here matters
- name: restart telegraf
service:
service:
name: telegraf
state: restarted

- name: pause
pause:
seconds: 3
seconds: "{{telegraf_start_delay}}"

## After version 2.2 of ansible 'listen' could be used to
## group 'check status' and 'assert running' into a single listener
- name: check status
command: service telegraf status
ignore_errors: yes
register: telegraf_service_status
- name: assert running
assert:
that:
- "telegraf_service_status.rc == 0"
31 changes: 6 additions & 25 deletions tasks/configure.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@
group: telegraf
mode: 0744
when: telegraf_template_configuration
# If config changes, restart telegraf and confirm it remained running
notify:
- "restart telegraf"
- "pause"
- "check status"
- "assert running"

- name: Test for sysvinit script
stat:
Expand All @@ -31,28 +37,3 @@
- name: Reload systemd configuration [systemd]
command: systemctl daemon-reload
when: telegraf_unit_file_updated is defined and telegraf_unit_file_updated.changed

- name: Start the Telegraf service
service:
name: telegraf
state: restarted
enabled: yes
register: telegraf_started
when: telegraf_start_service

- name: Pause to ensure Telegraf service is up
pause:
seconds: 6
when: telegraf_started.changed and telegraf_start_service

- name: Collect service status
command: service telegraf status
register: telegraf_service_status
when: telegraf_start_service
ignore_errors: yes

- name: Assert status of Telegraf service
assert:
that:
- "telegraf_service_status.rc == 0"
when: telegraf_start_service
4 changes: 4 additions & 0 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,7 @@

- include: configure.yml
tags: [telegraf, configure]

- include: start.yml
tags: [telegraf, start]
when: telegraf_start_service
11 changes: 11 additions & 0 deletions tasks/start.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

- name: Start the Telegraf service
service:
name: telegraf
state: started
enabled: yes
# Only care to check the status if the state changed to 'started'
notify:
- "pause"
- "check status"
- "assert running"
1 change: 1 addition & 0 deletions vars/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ is_vagrant: no

# If yes, service will be started. Will not be started if set to no.
telegraf_start_service: yes
telegraf_start_delay: 6

# If yes, will overwrite the packaged configuration with an Asnible/jinja2 template
telegraf_template_configuration: yes
Expand Down

0 comments on commit 1024bf4

Please sign in to comment.