我有一个剧本,它在 Windows 机器上执行一个脚本,该脚本返回一个值,切换到localhost.
切换回后如何访问该值localhost?
这是一个例子:
- hosts: windows
gather_facts: no
tasks:
- name: Call PowerShell script
win_command: "c:\\windows\\system32\\WindowsPowerShell\\v1.0\\powershell.exe c:\\psl_scripts\\getData.ps1"
register: value_to_reuse
- hosts: localhost
gather_facts: no
tasks:
- name: debug store_name from windows host
debug:
var: "{{ hostvars[windows][value_to_reuse][stdout_lines] }}"
Run Code Online (Sandbox Code Playgroud)
从另一台主机访问变量的正确语法是什么?我收到错误消息:
"msg": "该任务包含一个带有未定义变量的选项。错误是:'windows' 未定义
我有一个管理系统,我们在其中定义维护数据来控制虚拟环境,其中一个选项是不同团队的 VM 关闭时间范围。现在,当创建新的 VM 时,用户应该从可用的时间范围列表中选择他/她的 VM 可以在不中断工作班次的情况下关闭的时间。我需要能够将这个时间范围列表从我的数据库同步到工作模板调查。我一直在修改 JSON 调查。我已经尝试了这篇文章在ansible中修改json的最佳方法,但出现错误:
“异常”:“文件\”/tmp/ansible_1qa8eR/ansible_module_json_modify.py\”,第38行,在main\n res = jsonpointer.resolve_pointer(data, pointer)\n File \”/usr/lib/python2.7/ site-packages/jsonpointer.py\", line 126, in resolve_pointer\n return pointer.resolve(doc, default)\n File \"/usr/lib/python2.7/site-packages/jsonpointer.py\",第 204 行,在解析中\n doc = self.walk(doc, part)\n 文件 \"/usr/lib/python2.7/site-packages/jsonpointer.py\",第 279 行,在 walk 中\n 引发 JsonPointerException (\"在 %s 中找不到成员 '%s'\" % (part, doc))\n", "msg": "在 {'stderr_lines': [], 'changed' 中找不到成员 'spec':真的,'结束'
这是我要修改的 JSON:
{
"spec": [
{
"question_description": "",
"min": 0,
"default": "Test text",
"max": 4096,
"required": true,
"choices": "",
"variable": "_t",
"question_name": "Note",
"type": …Run Code Online (Sandbox Code Playgroud)