�
�Udac @` s� d d l m Z m Z m Z e Z i d d 6d g d 6d d 6Z d Z d Z d d
l m
Z
d d l m Z d d l
m Z d d
� Z d � Z e d k r� e � n d S( i ( t absolute_importt divisiont print_functions 1.1t metadata_versiont previewt statust communityt supported_bysE
---
version_added: "1.6"
module: twilio
short_description: Sends a text message to a mobile phone through Twilio.
description:
- Sends a text message to a phone number through the Twilio messaging API.
notes:
- This module is non-idempotent because it sends an email through the
external API. It is idempotent only in the case that the module fails.
- Like the other notification modules, this one requires an external
dependency to work. In this case, you'll need a Twilio account with
a purchased or verified phone number to send the text message.
options:
account_sid:
description:
user's Twilio account token found on the account page
required: true
auth_token:
description: user's Twilio authentication token
required: true
msg:
description:
the body of the text message
required: true
to_numbers:
description:
one or more phone numbers to send the text message to,
format +15551112222
required: true
aliases: [ to_number ]
from_number:
description:
the Twilio number to send the text message from, format +15551112222
required: true
media_url:
description:
a URL with a picture, video or sound clip to send with an MMS
(multimedia message) instead of a plain SMS
required: false
author: "Matt Makai (@makaimc)"
sV
# 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
- 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
- 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
- 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
( t
AnsibleModule( t urlencode( t fetch_urlc C` s� d | f } d } i | d 6| d 6| d 6} | rA | | d <n t | � }
i | d 6d d 6d
d 6} | j d d
� | j d <| j d d
� | j d <t | | d |
d | �S( Ns; https://api.twilio.com/2010-04-01/Accounts/%s/Messages.jsont Ansiblet Fromt Tot Bodyt MediaUrls
User-Agents! application/x-www-form-urlencodeds Content-types application/jsont Accepts
t t url_usernamet url_passwordt datat headers( R t replacet paramsR
( t modulet account_sidt
auth_tokent msgt from_numbert to_numbert media_urlt URIt AGENTR t encoded_dataR ( ( sG /usr/lib/python2.7/site-packages/ansible/modules/notification/twilio.pyt post_twilio_apil s
c C` s� t d t d t d t � d t d t d t � d t d t � d t d t � d t d t d d
g d d � d
t d d d t � � d t � } | j d } | j d } | j d } | j d } | j d } | j d
} x� | D]� } t | | | | | | | � \ } } | d d k r� d }
d | k rN| j | d � } | d }
n | j d d | |
f � q� q� W| j d | d t � d S( Nt
argument_specR t requiredR t no_logR R t
to_numberst aliasesR t typet listR t defaultt supports_check_modeR i� i� s
unknown errort bodyt messages unable to send message to %s: %st changed( i� i� (
R t dictt Truet Nonet FalseR R"