为什么 Ansible 找不到系统路径中的可执行文件?

问题描述 投票:0回答:2

Ansible v2.11 目标:Windows 2012 Server

我正在尝试使用

C:\Program Files\7-zip\7z.exe
实用程序解压缩文件,并且该文件夹位于系统路径中。由于文件名太长,我无法使用
win_unzip
。不过我明白了?

- name: "Unzip exa-web {{ exa_web_zip }}"
  win_command:
    7z x {{ remote_dir }}/{{ exa_web_zip }} -o{{ exa_web_dir }}

TASK [exa-web : Unzip exa-web exa-web-development-b7cf4eee3c-20210930_1700-win64.zip] ***
fatal: [172.16.100.31]: FAILED! => {"changed": false, "cmd": "7z x C:\\temp/exa-web-development-b7cf4eee3c-20210930_1700-win64.zip -oC:\\Viztek\\EXA\\web", "msg": "Exception calling \"SearchPath\" with \"1\" argument(s): \"Could not find file '7z.exe'.\"", "rc": 2}

我什至添加了此任务只是为了确保它位于系统路径中,但无济于事。

- name: Add to system path
  win_path:
    elements:
      - "C:\\Program Filse\\7-zip"

我错过了什么?

windows ansible 7zip
2个回答
1
投票

有一个你应该使用的通用参数,它被称为

chdir
。然后ansible应该找到可执行文件:

- name: "Unzip exa-web {{ exa_web_zip }}"
  win_command:
    7z x {{ remote_dir }}/{{ exa_web_zip }} -o{{ exa_web_dir }}
  args:
    chdir: 'C:\Program Filse\7-zip'

0
投票

您可以将环境变量保存在

.profile
中然后使用

ansible all -m shell -a '. /etc/profile;<command>' -b

<command>
替换为您想要执行的任何操作。

© www.soinside.com 2019 - 2024. All rights reserved.