community.general.twilio 模块 – 通过 Twilio 发送短信到手机

注意

此模块是 community.general 集合 (版本 10.1.0) 的一部分。

如果您使用的是 ansible 包,则可能已经安装了此集合。它不包含在 ansible-core 中。要检查它是否已安装,请运行 ansible-galaxy collection list

要安装它,请使用: ansible-galaxy collection install community.general

要在 playbook 中使用它,请指定: community.general.twilio

概要

  • 通过 Twilio 消息 API 发送短信到电话号码。

参数

参数

注释

account_sid

字符串 / 必需

用户在帐户页面上找到的 Twilio 帐户令牌。

auth_token

字符串 / 必需

用户的 Twilio 身份验证令牌。

from_number

字符串 / 必需

要从中发送短信的 Twilio 号码,格式为 +15551112222

media_url

字符串

包含图片、视频或声音片段的 URL,用于发送 MMS(多媒体消息)而不是普通短信。

msg

字符串 / 必需

短信正文。

to_numbers

别名:to_number

列表 / 元素=字符串 / 必需

一个或多个要发送短信的电话号码,格式为 +15551112222

属性

属性

支持

描述

check_mode

支持:完全支持

可以在 check_mode 下运行,并在不修改目标的情况下返回更改状态预测。

diff_mode

支持:不支持

处于 diff 模式时,将返回有关已更改内容(或可能需要在 check_mode 中更改的内容)的详细信息。

备注

注意

  • 此模块是非幂等的,因为它通过外部 API 发送电子邮件。只有在模块失败的情况下,它才是幂等的。

  • 与其他通知模块一样,此模块需要外部依赖项才能工作。在这种情况下,您需要一个 Twilio 帐户以及已购买或已验证的电话号码才能发送短信。

示例

# send an SMS about the build status to (555) 303 5681
# note: replace account_sid and auth_token values with your credentials
# and you have to have the 'from_number' on your Twilio account
- name: Send a text message to a mobile phone through Twilio
  community.general.twilio:
    msg: All servers with webserver role are now configured.
    account_sid: ACXXXXXXXXXXXXXXXXX
    auth_token: ACXXXXXXXXXXXXXXXXX
    from_number: +15552014545
    to_number: +15553035681
  delegate_to: localhost

# send an SMS to multiple phone numbers about the deployment
# note: replace account_sid and auth_token values with your credentials
# and you have to have the 'from_number' on your Twilio account
- name: Send a text message to a mobile phone through Twilio
  community.general.twilio:
    msg: This server configuration is now complete.
    account_sid: ACXXXXXXXXXXXXXXXXX
    auth_token: ACXXXXXXXXXXXXXXXXX
    from_number: +15553258899
    to_numbers:
      - +15551113232
      - +12025551235
      - +19735559010
  delegate_to: localhost

# send an MMS to a single recipient with an update on the deployment
# and an image of the results
# note: replace account_sid and auth_token values with your credentials
# and you have to have the 'from_number' on your Twilio account
- name: Send a text message to a mobile phone through Twilio
  community.general.twilio:
    msg: Deployment complete!
    account_sid: ACXXXXXXXXXXXXXXXXX
    auth_token: ACXXXXXXXXXXXXXXXXX
    from_number: +15552014545
    to_number: +15553035681
    media_url: https://demo.twilio.com/logo.png
  delegate_to: localhost

作者

  • Matt Makai (@makaimc)