#include <MsgBoxConstants.au3> ; to declare the Constants of MsgBox
Local $sRegex = "(?m)^DOCUMENTATION.*(\"{3}|'{3})\n-*\n?([\s\S]+?)^\1[\s\S]*"
Local $sString = "#!/usr/bin/python" & @CRLF & _
"# -*- coding: utf-8 -*-" & @CRLF & _
"" & @CRLF & _
"# (c) 2014, Ramon de la Fuente <ramon@delafuente.nl>" & @CRLF & _
"#" & @CRLF & _
"# This file is part of Ansible" & @CRLF & _
"#" & @CRLF & _
"# Ansible is free software: you can redistribute it and/or modify" & @CRLF & _
"# it under the terms of the GNU General Public License as published by" & @CRLF & _
"# the Free Software Foundation, either version 3 of the License, or" & @CRLF & _
"# (at your option) any later version." & @CRLF & _
"#" & @CRLF & _
"# Ansible is distributed in the hope that it will be useful," & @CRLF & _
"# but WITHOUT ANY WARRANTY; without even the implied warranty of" & @CRLF & _
"# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the" & @CRLF & _
"# GNU General Public License for more details." & @CRLF & _
"#" & @CRLF & _
"# You should have received a copy of the GNU General Public License" & @CRLF & _
"# along with Ansible. If not, see <http://www.gnu.org/licenses/>." & @CRLF & _
"" & @CRLF & _
"DOCUMENTATION = """" & @CRLF & _
"module: slack" & @CRLF & _
"short_description: Send Slack notifications" & @CRLF & _
"description:" & @CRLF & _
" - The M(slack) module sends notifications to U(http://slack.com) via the Incoming WebHook integration" & @CRLF & _
"version_added: 1.6" & @CRLF & _
"author: Ramon de la Fuente <ramon@delafuente.nl>" & @CRLF & _
"options:" & @CRLF & _
" domain:" & @CRLF & _
" description:" & @CRLF & _
" - Slack (sub)domain for your environment without protocol." & @CRLF & _
" (i.e. C(future500.slack.com))" & @CRLF & _
" required: true" & @CRLF & _
" token:" & @CRLF & _
" description:" & @CRLF & _
" - Slack integration token" & @CRLF & _
" required: true" & @CRLF & _
" msg:" & @CRLF & _
" description:" & @CRLF & _
" - Message to send." & @CRLF & _
" required: true" & @CRLF & _
" channel:" & @CRLF & _
" description:" & @CRLF & _
" - Channel to send the message to. If absent, the message goes to the channel selected for the I(token)." & @CRLF & _
" required: false" & @CRLF & _
" username:" & @CRLF & _
" description:" & @CRLF & _
" - This is the sender of the message." & @CRLF & _
" required: false" & @CRLF & _
" default: ansible" & @CRLF & _
" icon_url:" & @CRLF & _
" description:" & @CRLF & _
" - Url for the message sender's icon (default C(http://www.ansible.com/favicon.ico))" & @CRLF & _
" required: false" & @CRLF & _
" icon_emoji:" & @CRLF & _
" description:" & @CRLF & _
" - Emoji for the message sender. See Slack documentation for options." & @CRLF & _
" (if I(icon_emoji) is set, I(icon_url) will not be used)" & @CRLF & _
" required: false" & @CRLF & _
" link_names:" & @CRLF & _
" description:" & @CRLF & _
" - Automatically create links for channels and usernames in I(msg)." & @CRLF & _
" required: false" & @CRLF & _
" default: 1" & @CRLF & _
" choices:" & @CRLF & _
" - 1" & @CRLF & _
" - 0" & @CRLF & _
" parse:" & @CRLF & _
" description:" & @CRLF & _
" - Setting for the message parser at Slack" & @CRLF & _
" required: false" & @CRLF & _
" choices:" & @CRLF & _
" - 'full'" & @CRLF & _
" - 'none'" & @CRLF & _
" validate_certs:" & @CRLF & _
" description:" & @CRLF & _
" - If C(no), SSL certificates will not be validated. This should only be used" & @CRLF & _
" on personally controlled sites using self-signed certificates." & @CRLF & _
" required: false" & @CRLF & _
" default: 'yes'" & @CRLF & _
" choices:" & @CRLF & _
" - 'yes'" & @CRLF & _
" - 'no'" & @CRLF & _
""""" & @CRLF & _
"" & @CRLF & _
"EXAMPLES = """" & @CRLF & _
"- name: Send notification message via Slack" & @CRLF & _
" local_action:" & @CRLF & _
" module: slack" & @CRLF & _
" domain: future500.slack.com" & @CRLF & _
" token: thetokengeneratedbyslack" & @CRLF & _
" msg: "{{ inventory_hostname }} completed"" & @CRLF & _
"" & @CRLF & _
"- name: Send notification message via Slack all options" & @CRLF & _
" local_action:" & @CRLF & _
" module: slack" & @CRLF & _
" domain: future500.slack.com" & @CRLF & _
" token: thetokengeneratedbyslack" & @CRLF & _
" msg: "{{ inventory_hostname }} completed"" & @CRLF & _
" channel: "#ansible"" & @CRLF & _
" username: "Ansible on {{ inventory_hostname }}"" & @CRLF & _
" icon_url: "http://www.example.com/some-image-file.png"" & @CRLF & _
" link_names: 0" & @CRLF & _
" parse: 'none'" & @CRLF & _
"" & @CRLF & _
""""" & @CRLF & _
"" & @CRLF & _
"" & @CRLF & _
"SLACK_INCOMING_WEBHOOK = 'https://%s/services/hooks/incoming-webhook?token=%s'" & @CRLF & _
"" & @CRLF & _
"def build_payload_for_slack(module, text, channel, username, icon_url, icon_emoji, link_names, parse):" & @CRLF & _
" payload = dict(text=text)" & @CRLF & _
"" & @CRLF & _
" if channel is not None:" & @CRLF & _
" payload['channel'] = channel if (channel[0] == '#') else '#'+channel" & @CRLF & _
" if username is not None:" & @CRLF & _
" payload['username'] = username" & @CRLF & _
" if icon_emoji is not None:" & @CRLF & _
" payload['icon_emoji'] = icon_emoji" & @CRLF & _
" else:" & @CRLF & _
" payload['icon_url'] = icon_url" & @CRLF & _
" if link_names is not None:" & @CRLF & _
" payload['link_names'] = link_names" & @CRLF & _
" if parse is not None:" & @CRLF & _
" payload['parse'] = parse" & @CRLF & _
"" & @CRLF & _
" payload="payload=" + module.jsonify(payload)" & @CRLF & _
" return payload" & @CRLF & _
"" & @CRLF & _
"def do_notify_slack(module, domain, token, payload):" & @CRLF & _
" slack_incoming_webhook = SLACK_INCOMING_WEBHOOK % (domain, token)" & @CRLF & _
"" & @CRLF & _
" response, info = fetch_url(module, slack_incoming_webhook, data=payload)" & @CRLF & _
" if info['status'] != 200:" & @CRLF & _
" obscured_incoming_webhook = SLACK_INCOMING_WEBHOOK % (domain, '[obscured]')" & @CRLF & _
" module.fail_json(msg=" failed to send %s to %s: %s" % (payload, obscured_incoming_webhook, info['msg']))" & @CRLF & _
"" & @CRLF & _
"def main():" & @CRLF & _
" module = AnsibleModule(" & @CRLF & _
" argument_spec = dict(" & @CRLF & _
" domain = dict(type='str', required=True)," & @CRLF & _
" token = dict(type='str', required=True)," & @CRLF & _
" msg = dict(type='str', required=True)," & @CRLF & _
" channel = dict(type='str', default=None)," & @CRLF & _
" username = dict(type='str', default='Ansible')," & @CRLF & _
" icon_url = dict(type='str', default='http://www.ansible.com/favicon.ico')," & @CRLF & _
" icon_emoji = dict(type='str', default=None)," & @CRLF & _
" link_names = dict(type='int', default=1, choices=[0,1])," & @CRLF & _
" parse = dict(type='str', default=None, choices=['none', 'full'])," & @CRLF & _
"" & @CRLF & _
" validate_certs = dict(default='yes', type='bool')," & @CRLF & _
" )" & @CRLF & _
" )" & @CRLF & _
"" & @CRLF & _
" domain = module.params['domain']" & @CRLF & _
" token = module.params['token']" & @CRLF & _
" text = module.params['msg']" & @CRLF & _
" channel = module.params['channel']" & @CRLF & _
" username = module.params['username']" & @CRLF & _
" icon_url = module.params['icon_url']" & @CRLF & _
" icon_emoji = module.params['icon_emoji']" & @CRLF & _
" link_names = module.params['link_names']" & @CRLF & _
" parse = module.params['parse']" & @CRLF & _
"" & @CRLF & _
" payload = build_payload_for_slack(module, text, channel, username, icon_url, icon_emoji, link_names, parse)" & @CRLF & _
" do_notify_slack(module, domain, token, payload)" & @CRLF & _
"" & @CRLF & _
" module.exit_json(msg="OK")" & @CRLF & _
"" & @CRLF & _
"# import module snippets" & @CRLF & _
"from ansible.module_utils.basic import *" & @CRLF & _
"from ansible.module_utils.urls import *" & @CRLF & _
"main()"
Local $sSubst = "---\n\3"
Local $sResult = StringRegExpReplace($sString, $sRegex, $sSubst)
MsgBox($MB_SYSTEMMODAL, "Result", $sResult)
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for AutoIt, please visit: https://www.autoitscript.com/autoit3/docs/functions/StringRegExp.htm