0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

AnsibleのジョブからTeamsにメッセージを送信する方法

Last updated at Posted at 2022-01-18

はじめに

AnsibleのジョブからTeamsにメッセージを送信する場合、uriモジュールを利用してPOSTすることもできると思いますが、 office_365_connector_cardモジュール を利用すると簡単に実装できます。

office_365_connector_cardモジュール

ドキュメント

https://docs.ansible.com/ansible/latest/collections/community/general/office_365_connector_card_module.html

事前準備

通知用のTeamsチャネルのコネクタにIncoming Webhookを構成しておきます。

モジュールの使い方

Ansible単体で利用する場合はモジュールをインストールしておきます。
https://rheb.hatenablog.com/entry/ansible_collections

Ansible Tower/AWXの場合はcollections/requirements.yml に community.general を追加しておきます。

collections/requirements.yml
---
collections:
- community.general # <--追加する

Playbookには以下のように記述します。

使い方
- name: Task Name
  community.general.office_365_connector_card:
    webhook: TeamsのIncoming Webhook URL #必須
    title: 件名                        #省略可
    text: 本文

実装例:作成したEC2のPublic DNS名をTeamsに通知する

サンプルコード

サンプルコード
〜略〜

# Send Teams Webhook
- name: Send Teams Webhook
  community.general.office_365_connector_card:
    webhook: "{{ teams_webhookurl }}"
    title: "あなたのWordPressが正常に作成されました。"
    text: "ようこそページにアクセスし利用を開始しましょう! http://{{ gather_ec2.instances[0].public_dns_name }}/wordpress/"
  register: teams_webhook
  delegate_to: localhost
  vars:
    ansible_connection: local

実行結果

Teamsに以下のように通知が届きます。
teams-adaptivecard2.png

おわりに

Ansibleは豊富なモジュールが提供されているので、積極的に利用することでPlaybook作成の効率化が期待できそうです。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?