Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Ansible とStackStorm でつくる ChatOps 環境

Ansible とStackStorm でつくる ChatOps 環境

Ansible Night in Tokyo 2018.04 (https://ansible-users.connpass.com/event/84907/ ) で話した資料です。

katsuhisa_

April 26, 2018
Tweet

More Decks by katsuhisa_

Other Decks in Technology

Transcript

  1. ぼく がちゃがちゃ(対応作業) ぼく 「こんな感じでした〜」(実行結果共有) --- 数分後 --- 監視ツール 「【Resolved】<ALERT> SERVER001

    !!」 ぼく 「おつかれさまでした〜」 Aさん 「おつかれ〜」 ある日のSlack でのコミュニケーション
  2. 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
  3. 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
  4. --- name: chatops.ansible_server_status action_ref: st2_chatops_aliases.server_status description: Show status for hosts

    (ansible ping module) formats: - display: "status <hosts>" 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 エイリアス定義
  5. --- 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 実行の内容
  6. --- 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\""