在本地文件中保存可见变量



我正在windows主机上执行PS脚本,并希望将其标准输出存储在一个可见的本地机器上的文件中。我有一个剧本如下:

---
- name: Check Antivirus software
hosts: all
become: false
gather_facts: no
tasks:
- name: Get AV details
win_shell: |
echo "script printing data on stdout"
register: result
- name: save response
copy:
content: '{{ result.stdout }}'
dest: '{{ response_file }}'
delegate_to: localhost

在上面的剧本中,第一个任务被执行,没有任何问题。但是第二个任务给出了以下错误:

TASK [save response] *******************************************************************************************************************************************
fatal: [20.15.102.192 -> localhost]: UNREACHABLE! => {"changed": false, "msg": "ntlm: HTTPSConnectionPool(host='localhost', port=5986): Max retries exceeded with url: /wsman (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7f4940760208>: Failed to establish a new connection: [Errno 111] Connection refused',))", "unreachable": true}

我也尝试了local_action,它也给出了相同的错误。

使用fetch_module代替copy_module然后你可能不需要&;delegate_to: localhost&;埃莫雷·

- name: save response
ansible.builtin.fetch:
content: '{{ result.stdout }}'
dest: '{{ response_file }}'

最新更新