I run Ansible task on remote Windows hosts. I want recieve result messages by Telegram, but by default these hosts not contains python, and Telegram module don’t work. How i can run it locally?
For example…
- hosts: winservers
vars:
scope: win
script: Rulez.PS1
folder: C:TEMP
gather_facts: false
vars_files:
- /etc/ansible/win/group_vars/{{ scope }}.sec
tasks:
- name: Сheck for path {{ folder }} availability. Create if not present.
win_file:
path: "{{ folder }}"
state: directory
After running i want get message in Telegram: Task finished at {{ ansible_hostname }}
Try insert this code in playbook
- hosts: 127.0.0.1
connection: local
gather_facts: false
tasks:
telegram:
token: 'tokentokentokentokentoken'
chat_id: 1234567890
msg: Task finished at {{ ansible_hostname }}
But it didn’t work. Besides, this way i get ansible_hostname as localhost
2
Answers
Please try as below. (not tested)
As per my knowledge ‘ansible_hostname’ won’t work if you disable gather_facts: False. and i still dont recommend to enable that option.. Try {{ hostvars[‘winservers’][‘inventory_hostname’] }} for your exact requirement.