Hello again!
Today i try to set an notification via Rocketchat again:
Im at an wokflow to update ubuntu clients and the last step was to get which one needs an reboot.
This part is done and then i thought it would bet better to sent the hosts via rocketchat - i aleready created an user for awx in RC and an channel and an webhook.
I have normal notivcation aleready configured for RC, when an Workflow needs apporoval for example.
My playbook:
---
- name: Check pending reboots on Ubuntu hosts using hostname command
hosts: all
gather_facts: yes
tasks:
- name: Check if /var/run/reboot-required exists
ansible.builtin.stat:
path: /var/run/reboot-required
register: reboot_file
no_log: true
- name: Stop play if /var/run/reboot-required does not exist
ansible.builtin.meta: end_host
when: not reboot_file.stat.exists
no_log: true
- name: Check reboot
ansible.builtin.shell: "cat /var/run/reboot-required"
register: pending_reboot
no_log: true
- name: Stop play for hosts without pending reboot
ansible.builtin.meta: end_host
when: pending_reboot.stdout is not defined or pending_reboot.stdout | length == 0
no_log: true
- name: Retrieve the hostname from the client
ansible.builtin.command: hostname
register: client_hostname
changed_when: false
tags: check_reboot
no_log: true
- name: Debug output for hosts with pending reboots
ansible.builtin.debug:
msg: >
Host {{ client_hostname.stdout }} has a pending reboot.
- name: send hosts with pending reboot via rocketchat
community.general.rocketchat:
domain: chat.gruen.net
token: 'my/supersecuretoken'
msg: 'Host {{ client_hostname.stdout }} has a pending reboot.'
channel: '#AWX_Bot_Channel'
username: 'AWX_Bot'
#icon_url: http://www.example.com/some-image-file.png
#link_names: 0
delegate_to: localhost
And i get for this task:
TASK [send hosts with pending reboot via rocketchat] ***************************
task path: /runner/project/functions/updates/lin/apt/pending_reboot.yaml:40
<localhost> ESTABLISH LOCAL CONNECTION FOR USER: 1000
<localhost> EXEC /bin/sh -c 'echo ~1000 && sleep 0'
<localhost> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /runner/.ansible/tmp `"&& mkdir "` echo /runner/.ansible/tmp/ansible-tmp-1738057608.6749742-189-220025192254686 `" && echo ansible-tmp-1738057608.6749742-189-220025192254686="` echo /runner/.ansible/tmp/ansible-tmp-1738057608.6749742-189-220025192254686 `" ) && sleep 0'
Using module file /usr/share/ansible/collections/ansible_collections/community/general/plugins/modules/rocketchat.py
<localhost> PUT /runner/.ansible/tmp/ansible-local-22rs00qiu8/tmpegkl75hg TO /runner/.ansible/tmp/ansible-tmp-1738057608.6749742-189-220025192254686/AnsiballZ_rocketchat.py
<localhost> EXEC /bin/sh -c 'chmod u+x /runner/.ansible/tmp/ansible-tmp-1738057608.6749742-189-220025192254686/ /runner/.ansible/tmp/ansible-tmp-1738057608.6749742-189-220025192254686/AnsiballZ_rocketchat.py && sleep 0'
<localhost> EXEC /bin/sh -c '/usr/bin/python3 /runner/.ansible/tmp/ansible-tmp-1738057608.6749742-189-220025192254686/AnsiballZ_rocketchat.py && sleep 0'
<localhost> EXEC /bin/sh -c 'rm -f -r /runner/.ansible/tmp/ansible-tmp-1738057608.6749742-189-220025192254686/ > /dev/null 2>&1 && sleep 0'
fatal: [192.168.20.186 -> localhost]: FAILED! => {
"changed": false,
"invocation": {
"module_args": {
"attachments": null,
"channel": "#AWX_Bot_Channel",
"color": "normal",
"domain": "chat.gruen.net",
"icon_emoji": null,
"icon_url": "https://docs.ansible.com/favicon.ico",
"link_names": 1,
"msg": "Host DB-186 has a pending reboot.",
"protocol": "https",
"token": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
"username": "AWX_Bot",
"validate_certs": true
}
},
"msg": "failed to send message, return status=400"
}
I can sent messages directly from the host from the error - there is an default test message you can copy from the RC webhoock config for debug:
I ned some hints - im stuck in my head right now.
Thank you for your help again!