Slide 1

Slide 1 text

Ansible とStackStorm でつくる ChatOps 環境 Ansible Night in Tokyo 2018.04 株式会社スタディスト 北野 勝久

Slide 2

Slide 2 text

すきなAnsible モジュール  lineinfile : @katsuhisa__

Slide 3

Slide 3 text

突然ですが、 こんなことありませんか?

Slide 4

Slide 4 text

監視ツール 「<ALERT> SERVER001 !!」 ぼく 「アラートきた」 Aさん 「なんだなんだ」 ある日のSlack でのコミュニケーション

Slide 5

Slide 5 text

ぼく 「なんだこのアラートか」 Aさん 「なんだこのアラートか」 ぼく 「対応やっときますね」 Aさん 「よろしく」 ある日のSlack でのコミュニケーション

Slide 6

Slide 6 text

ぼく がちゃがちゃ(対応作業) ぼく 「こんな感じでした〜」(実行結果共有) --- 数分後 --- 監視ツール 「【Resolved】<ALERT> SERVER001 !!」 ぼく 「おつかれさまでした〜」 Aさん 「おつかれ〜」 ある日のSlack でのコミュニケーション

Slide 7

Slide 7 text

すぐに状況確認して、すぐに実行結果を共有したい ➔実行結果を共有するために ➔Slack と作業環境を行き来するの面倒 なんなら初動対応と結果共有すべて自動化したい ※うちのSRE チームの名誉のために書いておくと、 ※こういう類のものは、現時点でも自動復旧できるようになっている箇所も多いです

Slide 8

Slide 8 text

それ、StackStorm でできます

Slide 9

Slide 9 text

StackStorm? Event-Driven Automation StackStorm is a powerful open-source automation platform that wires together all of your apps, services and workflows. It’s extendable, flexible, and built with love for DevOps and ChatOps

Slide 10

Slide 10 text

StackStorm? Event-Driven Automation StackStorm is a powerful open-source automation platform that wires together all of your apps, services and workflows. It’s extendable, flexible, and built with love for DevOps and ChatOps ➔ IFTTT for Ops

Slide 11

Slide 11 text

IFTTT ? めっちゃかんたん。 「もし、this なら、that する。」以上。

Slide 12

Slide 12 text

IFTTT for Ops ? 例えば、こんな感じの世界になる IF THIS : もし、○○のアラートがきたら、 THEN THAT : Nginx を再起動して、PagerDuty にポスト

Slide 13

Slide 13 text

自動化できて幸せ

Slide 14

Slide 14 text

人の欲望には限りがない

Slide 15

Slide 15 text

そこまでできるんだったら・・・ アドホックなコマンド以外も実行したくなる Ansible に実装されているあれこれが使いたいとか なんならそもそもPlaybook を実行したいとか

Slide 16

Slide 16 text

それ、StackStorm でできます

Slide 17

Slide 17 text

検証してみた https://github.com/StackStorm/showcase-ansible-chatops

Slide 18

Slide 18 text

Ansible の 実行結果が表示

Slide 19

Slide 19 text

--- name: chatops.ansible_server_status action_ref: st2_chatops_aliases.server_status description: Show status for hosts (ansible ping module) formats: - display: "status " representation: - "status {{ hosts }}" - "ping {{ hosts }}" result: format: | Here is your status for `{{ execution.parameters.hosts }}` host(s): {~} ```{{ execution.result.stdout }}``` extra: slack: color: "{% if execution.result.succeeded %}good{% else %}danger{% endif %}" fields: - title: Alive value: "{{ execution.result.stdout|regex_replace('(?!SUCCESS).', '')|wordcount }}" short: true - title: Dead value: "{{ execution.result.stdout|regex_replace('(?!UNREACHABLE).', '')|wordcount }}" short: true footer: "{{ execution.id }}" footer_icon: "https://stackstorm.com/wp/wp-content/uploads/2015/01/favicon.png" aliases/server_status.yaml エイリアス定義

Slide 20

Slide 20 text

--- name: http_status_codes description: Show sorted http status codes from nginx logs runner_type: local-shell-cmd entry_point: "" enabled: true parameters: sudo: immutable: true default: true kwarg_op: immutable: true cmd: description: "Command to run" type: string immutable: true default: "/opt/stackstorm/virtualenvs/ansible/bin/ansible {{hosts|replace('http://','')}} --become -m shell -a \"awk '{print \\$9}' /var/log/nginx/access.log |sort |uniq -c |sort -k1,1nr 2>/dev/null|column -t\"" hosts: description: "Ansible hosts" type: string required: true actions/http_status_codes.yaml 実行の内容

Slide 21

Slide 21 text

--- name: http_status_codes description: Show sorted http status codes from nginx logs runner_type: local-shell-cmd entry_point: "" enabled: true parameters: sudo: immutable: true default: true kwarg_op: immutable: true cmd: description: "Command to run" type: string immutable: true default: "/opt/stackstorm/virtualenvs/ansible/bin/ansible {{hosts|replace('http://','')}} --become -m shell -a \"awk '{print \\$9}' /var/log/nginx/access.log |sort |uniq -c |sort -k1,1nr 2>/dev/null|column -t\"" hosts: description: "Ansible hosts" type: string required: true actions/http_status_codes.yaml 実行の内容 "/opt/stackstorm/virtualenvs/ansible/bin/ansible {{hosts|replace('http://','')}} --become -m shell -a \ "awk '{print \\$9}' /var/log/nginx/access.log |sort |uniq -c |sort -k1,1nr 2>/dev/null|column -t\""

Slide 22

Slide 22 text

\Ansible でたのしいChatOps ライフを/