James Tombleson
d14c2aaa2c
* docker tests are looking good and nfs is able to connect and containers can talk to each other. * Added pihole support for a new vm * pihole is not working yet via docker. Installed it by hand without ansible for now. * added some docker related tasks and working on collins now to see how to use it. * forgot to push some changes... kube didnt work out as it adds too much overhead for what I need. * added two roles to help working with backup and restore of docker volume data. * did some cleanup on old roles. * pushing for axw testing * moving to requirements.yml. adding cron jobs for maint. * roles are being moved out of this repo. Roles are handled by requirements.yml going forward. Dev roles are still in the repo but if they stick around a new repo will be made for it. * Made a bunch of changes * fixed a problem * Added a playbook to deploy grafana and added prometheus role to monitor things. * Updated cron to test * Updated cron to test * Updated cron * updated discord_webhook and now testing if cron will pick up the changes. * Fixed plex backup for now. * docker updates and working on nginx * pushing pending changes that need to go live for cron testing * fixed debug roles and updated discord test * fixed debug roles and updated discord test * Disabling test cron * its been awhile... I am not sure what I have done anymore but time to push my changes. * added newsbot configs, added to jenkins, starting to migrate to collections. * Updated inventory to support the network changes * jenkinsfile is now working in my local setup. * node2 is unhealthy and is removed from inv. I was doing something to this box months ago, but now i dont remember what it was." * updated images and adding them to jenkins for testing * removed the old image files and moved to my public image * Jenkins will now inform discord of jobs. Added post tasks. Added mediaserver common. * updated the backend update job and adding a jenkins pipeline to handle it for me. * updated the backup job again * Updated all the jekins jobs. Added a jenkins newsbot backup job. Adjusted newsbot plays to add backup and redeploy jobs. * updated newsbot backup playbook to make older backup files as needed. * Added debug message to report in CI what version is getting deployed. * I did something stupid and this device is not letting me login for now. * removing twitter source for now as I found a bandwidth related bug that wont get pushed for a bit * Adding a bunch of changes, some is cleanup and some are adds * updated the images * updated the kube common playbook * Started to work on ceph, stopped due to hardware resources, updated common, added monit, and starting to work on a playbook to handle my ssh access. * Added a role to deploy monit to my servers. Still needs some more updates before its ready * Here is my work on ceph, it might go away but I am not sure yet. * Starting to migrate my common playbook to a role, not done yet. * updated kube and inventory * updated gitignore
178 lines
4.8 KiB
Python
178 lines
4.8 KiB
Python
#!/usr/bin/python
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# Copyright: (c) 2019, James Tombleson <luther38@gmail.com>
|
|
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
|
|
|
|
|
|
|
from ansible.module_utils.basic import AnsibleModule
|
|
from ansible.module_args.urls import fetch_url
|
|
import json
|
|
|
|
ANSIBLE_METADATA = {
|
|
'metadata_version': '1.0',
|
|
'status': ['preview'],
|
|
'supported_by': 'community'
|
|
}
|
|
|
|
DOCUMENTATION = '''
|
|
---
|
|
module: discord_webhook
|
|
|
|
short_description: This module sends messages to a discord webhook.
|
|
|
|
version_added: "2.4"
|
|
|
|
description:
|
|
- "This is my longer description explaining my test module"
|
|
|
|
options:
|
|
webhook_url:
|
|
description:
|
|
- This defines where ansible will send the json payload for discord to intake.
|
|
required: true
|
|
content:
|
|
description:
|
|
- This defines the message that will be presented within the payload.
|
|
required: true
|
|
|
|
username:
|
|
description:
|
|
- This will allow you to overwrite the default webhook name.
|
|
- Useful for when different services use the same webhook.
|
|
required: false
|
|
|
|
avatar_url:
|
|
description:
|
|
- Add a URL here if you want to overwrite the default avatar image configured on the webhook.
|
|
required: false
|
|
|
|
|
|
author:
|
|
- James Tombleson (github.com/luther38)
|
|
'''
|
|
|
|
EXAMPLES = '''
|
|
# Pass in a message
|
|
- name: Test with a message
|
|
my_test:
|
|
name: hello world
|
|
|
|
# pass in a message and have changed true
|
|
- name: Test with a message and changed output
|
|
my_test:
|
|
name: hello world
|
|
new: true
|
|
|
|
# fail the module
|
|
- name: Test failure of the module
|
|
my_test:
|
|
name: fail me
|
|
'''
|
|
|
|
RETURN = '''
|
|
original_message:
|
|
description: The original name param that was passed in
|
|
type: str
|
|
returned: always
|
|
message:
|
|
description: The output message that the test module generates
|
|
type: str
|
|
returned: always
|
|
'''
|
|
|
|
|
|
def run_module():
|
|
# define available arguments/parameters a user can pass to the module
|
|
|
|
|
|
# seed the result dict in the object
|
|
# we primarily care about changed and state
|
|
# change is if this module effectively modified the target
|
|
# state will include any data that you want your module to pass back
|
|
# for consumption, for example, in a subsequent task
|
|
result = dict(
|
|
changed=False,
|
|
original_message='',
|
|
message=''
|
|
)
|
|
|
|
# the AnsibleModule object will be our abstraction working with Ansible
|
|
# this includes instantiation, a couple of common attr would be the
|
|
# args/params passed to the execution, as well as if the module
|
|
# supports check mode
|
|
module = AnsibleModule(
|
|
argument_spec=module_args,
|
|
supports_check_mode=True
|
|
)
|
|
|
|
# if the user is working with this module in only check mode we do not
|
|
# want to make any changes to the environment, just return the current
|
|
# state with no modifications
|
|
if module.check_mode:
|
|
module.exit_json(**result)
|
|
|
|
# manipulate or modify the state as needed (this is going to be the
|
|
# part where your module will do what it needs to do)
|
|
result['original_message'] = module.params['name']
|
|
result['message'] = 'goodbye'
|
|
|
|
# use whatever logic you need to determine whether or not this module
|
|
# made any modifications to your target
|
|
if module.params['new']:
|
|
result['changed'] = True
|
|
|
|
# during the execution of the module, if there is an exception or a
|
|
# conditional state that effectively causes a failure, run
|
|
# AnsibleModule.fail_json() to pass in the message and the result
|
|
if module.params['name'] == 'fail me':
|
|
module.fail_json(msg='You requested this to fail', **result)
|
|
|
|
# in the event of a successful module execution, you will want to
|
|
# simple AnsibleModule.exit_json(), passing the key/value results
|
|
module.exit_json(**result)
|
|
|
|
def basic(ansibleModule):
|
|
|
|
headers = '{ "Content-Type": "application/json" }'
|
|
payload = {
|
|
'content': ansibleModule.argument_spec['content']
|
|
}
|
|
resp, info = fetch_url(
|
|
module=payload,
|
|
url= ansibleModule.argument_spec['webhook_url'],
|
|
headers= json.loads(headers),
|
|
method='GET')
|
|
|
|
if info['status'] != 204:
|
|
ansibleModule.fail_json(msg="Fail: ")
|
|
|
|
pass
|
|
|
|
def main():
|
|
module = AnsibleModule(
|
|
argument_spec= dict(
|
|
webhook_url =dict(type='str', required=True),
|
|
content =dict(type='str', required=True),
|
|
username =dict(type='str', required=False),
|
|
avatar_url =dict(type='str', required=False)
|
|
),
|
|
supports_check_mode= True
|
|
)
|
|
|
|
result = dict(
|
|
changed= False,
|
|
original_message= '',
|
|
message= ''
|
|
)
|
|
|
|
if module.check_mode:
|
|
return result
|
|
|
|
basic(module)
|
|
|
|
#run_module()
|
|
|
|
if __name__ == '__main__':
|
|
main() |