-
-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #125 from StackStorm/st2chatops_role
Add st2chatops role
- Loading branch information
Showing
11 changed files
with
303 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# st2chatops version to install. Use `latest` to get automatic updates or pin it to numeric version like `2.2.0` | ||
st2chatops_version: latest | ||
|
||
# Please provide ST2_API_KEY using "st2 apikey create -k" | ||
st2chatops_st2_api_key: CHANGE-ME-PLEASE | ||
|
||
# Hubot Adapter to be used for st2chatops. | ||
# For supported adapters, please check: https://github.com/StackStorm/ansible-st2/blob/master/roles/st2chatops/vars/main.yml | ||
# | ||
# Example, for slack: st2chatops_hubot_adapter: slack | ||
st2chatops_hubot_adapter: shell | ||
|
||
# Hash to configure values for the adapter in "/opt/stackstorm/chatops/st2chatops.env" | ||
# Original: https://github.com/StackStorm/st2chatops/blob/master/st2chatops.env | ||
# | ||
# Example, for slack: st2chatops_config: {"HUBOT_SLACK_TOKEN":"xoxb-CHANGE-ME-PLEASE"} | ||
st2chatops_config: {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
- name: restart st2chatops | ||
become: yes | ||
service: | ||
name: st2chatops | ||
state: restarted |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
--- | ||
galaxy_info: | ||
description: Install st2chatops | ||
author: humblearner | ||
company: StackStorm | ||
license: Apache 2.0 | ||
min_ansible_version: 2.2 | ||
platforms: | ||
- name: Ubuntu | ||
versions: | ||
- trusty | ||
- xenial | ||
- name: EL | ||
versions: | ||
- 6 | ||
- 7 | ||
categories: | ||
- st2 | ||
- devops | ||
- chatops | ||
- automation | ||
- hubot | ||
dependencies: | ||
- role: nodejs | ||
- role: st2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
--- | ||
- name: Assert st2chatops_hubot_adapter is specified | ||
fail: | ||
msg: > | ||
'"st2chatops_hubot_adapter" must be one of the supported adapters in https://github.com/StackStorm/st2chatops/blob/master/st2chatops.env' | ||
when: st2chatops_hubot_adapter not in supported_hubot_adapters | ||
|
||
- name: Assert st2chatops_hubot_adapter "{{ st2chatops_hubot_adapter|upper }}" settings are specified | ||
fail: | ||
msg: '"st2chatops_config" hash cannot be empty for "{{ st2chatops_hubot_adapter|upper }}" hubot adapter.' | ||
when: st2chatops_config.keys() == [] and st2chatops_hubot_adapter != "shell" | ||
|
||
- name: Install latest st2chatops package | ||
become: yes | ||
package: | ||
name: st2chatops | ||
state: latest | ||
when: st2chatops_version == "latest" | ||
tags: [st2chatops, skip_ansible_lint] | ||
|
||
- name: Install pinned st2chatops package | ||
become: yes | ||
package: | ||
name: st2chatops={{ st2chatops_version }} | ||
state: present | ||
when: st2chatops_version != "latest" | ||
tags: [st2chatops, skip_ansible_lint] | ||
|
||
- name: Add st2_api_key in st2chatops.env | ||
become: yes | ||
replace: | ||
dest: /opt/stackstorm/chatops/st2chatops.env | ||
regexp: '(?<=ST2_API_KEY=)(.*)$' | ||
replace: '{{ st2chatops_st2_api_key }}' | ||
when: st2chatops_st2_api_key != 'CHANGE-ME-PLEASE' | ||
register: task_st2_api_key | ||
no_log: true | ||
notify: restart st2chatops | ||
tags: st2chatops | ||
|
||
- name: Comment Username, Password and Auth URL, if API_KEY provided | ||
become: yes | ||
replace: | ||
dest: /opt/stackstorm/chatops/st2chatops.env | ||
regexp: '{{ item }}' | ||
replace: '# \1' | ||
with_items: | ||
- '^(export ST2_AUTH_URL.*)' | ||
- '^(export ST2_AUTH_USERNAME.*)' | ||
- '^(export ST2_AUTH_PASSWORD.*)' | ||
when: task_st2_api_key.changed | ||
tags: [st2chatops, skip_ansible_lint] | ||
|
||
- name: Check if any adapter is enabled | ||
shell: "cat /opt/stackstorm/chatops/st2chatops.env | grep -e '^export HUBOT_ADAPTER=' " | ||
ignore_errors: True | ||
register: task_adapter_enabled | ||
changed_when: False | ||
|
||
- name: Set variable enabled_adapter | ||
set_fact: | ||
enabled_adapter: '{% set list_var = (task_adapter_enabled.stdout).split("=") %}{{ list_var[1] }}' | ||
ignore_errors: True | ||
changed_when: False | ||
|
||
- name: Comment existing hubot adapters in "/opt/stackstorm/chatops/st2chatops.env" | ||
become: yes | ||
replace: | ||
dest: /opt/stackstorm/chatops/st2chatops.env | ||
regexp: '^(export HUBOT_ADAPTER=.*)' | ||
replace: '# \1' | ||
when: 'enabled_adapter != "{{ st2chatops_hubot_adapter }}" or enabled_adapter is not defined' | ||
changed_when: no | ||
tags: st2chatops | ||
|
||
- name: Uncomment Hubot "{{ st2chatops_hubot_adapter|upper }}" adapter in "/opt/stackstorm/chatops/st2chatops.env" | ||
become: yes | ||
replace: | ||
dest: /opt/stackstorm/chatops/st2chatops.env | ||
regexp: '^# (export HUBOT_ADAPTER={{ st2chatops_hubot_adapter }})$' | ||
replace: '\1' | ||
changed_when: no | ||
notify: restart st2chatops | ||
tags: st2chatops | ||
|
||
- name: Add entry for "SHELL" adapter | ||
become: yes | ||
lineinfile: | ||
dest: /opt/stackstorm/chatops/st2chatops.env | ||
line: export HUBOT_ADAPTER=shell | ||
when: st2chatops_hubot_adapter == "shell" | ||
notify: restart st2chatops | ||
tags: st2chatops | ||
|
||
- name: Configure "{{ st2chatops_hubot_adapter|upper }}" adapter setttings in "/opt/stackstorm/chatops/st2chatops.env" | ||
become: yes | ||
ini_file: | ||
dest: /opt/stackstorm/chatops/st2chatops.env | ||
section: null | ||
option: 'export {{ _conf_option.key }}' | ||
value: '{{ _conf_option.value }}' | ||
no_extra_spaces: yes | ||
with_dict: '{{ st2chatops_config }}' | ||
loop_control: | ||
loop_var: _conf_option | ||
no_log: true | ||
notify: restart st2chatops | ||
tags: st2chatops | ||
|
||
- name: Ensure st2chatops service is enabled and running | ||
become: yes | ||
service: | ||
name: st2chatops | ||
enabled: yes | ||
tags: st2chatops |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
--- | ||
supported_hubot_adapters: | ||
- slack | ||
- hipchat | ||
- xmpp | ||
- flowdock | ||
- yammer | ||
- spark | ||
- irc | ||
- mattermost | ||
- matteruser | ||
- shell |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
- name: restart st2chatops | ||
become: yes | ||
service: | ||
name: st2chatops | ||
state: restarted |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
- name: Set variables and hubot adapter settings | ||
set_fact: | ||
st2chatops_api_key: "{{ st2chatops_api_key }}" | ||
st2chatops_hubot_adapter: "{{ st2chatops_hubot_adapter }}" | ||
st2chatops_config: "{{ st2chatops_config }}" | ||
changed_when: no | ||
no_log: true | ||
tags: | ||
- smoke-tests | ||
|
||
- name: Install st2 pack from exchange | ||
become: yes | ||
environment: | ||
ST2_AUTH_TOKEN: "{{ ST2_AUTH_TOKEN }}" | ||
command: "st2 pack install st2" | ||
changed_when: no | ||
tags: | ||
- smoke-tests | ||
|
||
- name: Update st2_api_key in st2chatops.env | ||
become: yes | ||
replace: | ||
dest: /opt/stackstorm/chatops/st2chatops.env | ||
regexp: '(?<=ST2_API_KEY=)(.*)$' | ||
replace: '{{ st2chatops_api_key }}' | ||
no_log: true | ||
changed_when: no | ||
tags: | ||
- smoke-tests | ||
|
||
- name: Comment Username, Password and Auth URL, if API_KEY provided | ||
become: yes | ||
replace: | ||
dest: /opt/stackstorm/chatops/st2chatops.env | ||
regexp: '{{ item }}' | ||
replace: '# \1' | ||
with_items: | ||
- '^(export ST2_AUTH_URL.*)' | ||
- '^(export ST2_AUTH_USERNAME.*)' | ||
- '^(export ST2_AUTH_PASSWORD.*)' | ||
tags: | ||
- smoke-tests | ||
|
||
- name: Comment existing hubot adapters in "/opt/stackstorm/chatops/st2chatops.env" | ||
become: yes | ||
replace: | ||
dest: /opt/stackstorm/chatops/st2chatops.env | ||
regexp: '^(export HUBOT_ADAPTER=.*)' | ||
replace: '# \1' | ||
changed_when: no | ||
tags: | ||
- smoke-tests | ||
|
||
- name: Update "{{ st2chatops_hubot_adapter|upper }}" adapter | ||
become: yes | ||
replace: | ||
dest: /opt/stackstorm/chatops/st2chatops.env | ||
regexp: '^# (export HUBOT_ADAPTER={{ st2chatops_hubot_adapter }})$' | ||
replace: '\1' | ||
changed_when: no | ||
tags: | ||
- smoke-tests | ||
|
||
- name: Configure "{{ st2chatops_hubot_adapter|upper }}" settings | ||
become: yes | ||
ini_file: | ||
dest: /opt/stackstorm/chatops/st2chatops.env | ||
section: null | ||
option: 'export {{ _conf_option.key }}' | ||
value: '{{ _conf_option.value }}' | ||
no_extra_spaces: yes | ||
with_dict: '{{ st2chatops_config }}' | ||
loop_control: | ||
loop_var: _conf_option | ||
no_log: true | ||
notify: restart st2chatops | ||
tags: | ||
- smoke-tests | ||
|
||
- meta: flush_handlers | ||
tags: | ||
- smoke-tests | ||
|
||
- name: Verify st2chatops using bin/hubot | ||
command: "timeout 10 bin/hubot" | ||
args: | ||
chdir: "/opt/stackstorm/chatops/" | ||
register: test_output | ||
failed_when: "'{{ st2chatops_hubot_adapter|title }} client now connected' not in test_output.stdout or 'DEBUG Added command: st2 list' not in test_output.stdout" | ||
changed_when: no | ||
tags: | ||
- smoke-tests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,4 +11,5 @@ | |
- nginx | ||
- st2web | ||
- nodejs | ||
- st2chatops | ||
- st2smoketests |