ansible - Ansible.在远程/之后本地运行任务
问题描述
我在远程 Windows 主机上运行 Ansible 任务。我想通过 Telegram 接收结果消息,但默认情况下,这些主机不包含 python,并且 Telegram 模块不起作用。我如何在本地运行它?例如...
- 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
运行后,我想在 Telegram 中获取消息:Task finished at {{ ansible_hostname }} 尝试将此代码插入剧本
- hosts: 127.0.0.1
connection: local
gather_facts: false
tasks:
telegram:
token: 'tokentokentokentokentoken'
chat_id: 1234567890
msg: Task finished at {{ ansible_hostname }}
但它没有用。此外,这样我得到 ansible_hostname 作为 localhost
解决方案
请尝试如下。(未测试)
- 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
- name: send a message to chat in playbook
telegram:
token: 'tokentokentokentokentoken'
chat_id: 1234567890
msg: Task finished at {{ ansible_hostname }}
delegate_to: localhost
推荐阅读
- c - 在c中证明指针地址
- android - 使用 GeoFirestore 和 Firestore 过滤结果
- .net - 使用 AWS .NET Mock Lambda 测试工具在本地调试使用 .NET Core 创建的 AWS lambda 服务
- amazon-web-services - 使用新域名的 AWS 路由 53 重定向
- php - 在 php 中膨胀使用 ZLIB_ENCODING_DEFLATE 编码的数据
- php - 将文件上传到远程 FTP 服务器错误
- python - 使用 Keras ImageDataGenerator for Images 处理超过 3 个通道的数据
- java - 不知道如何获取当前位置并显示附近的汽车服务(工作坊)
- c# - 每个 DataRow 的奇怪输出。添加到 Excel
- angular - 在 Angular 8 数据输入数据绑定不起作用?