Ansible

可靠的和rrno2和rrn這2Errno 2路徑名中的文件或目錄不存在

  • December 23, 2021

我正在通過 ansible 塔執行以下程式碼:

command:
  chdir={{ __iim_install_location }}/eclipse/tools/
  "su - {{ __was_user }} -c {{ __iim_install_location }}/eclipse/tools/imcl install {{ __product_id }} -acceptLicense -repositories {{ __tmp_dir }}/{{ item.file_name }} -installationDirectory {{ __was_install_location}} -log {{ __log_file }}"
register:      cout
with_items:    "{{ __was_this_files }}"
changed_when:  cout.stdout is defined and ( cout.stdout.find( __version_check ) != -1)

我收到以下錯誤。我驗證並且所有路徑都存在於遠端主機中。

{
   "ansible_loop_var": "item",
   "_ansible_no_log": false,
   "changed": false,
   "item": {
       "check_sum": "866C82D13C24189E880C70AF7AE20143851330AD1C090E0DCF687B612BBC8513",
       "file_name": "8.5.5.16-ws-was-ifph42899.zip"
   },
   "cmd": "'su - was -c /opt/IBM/was/InstallationManager/eclipse/tools/imcl install 8.5.5.16-WS-WAS-IFPH42899_8.5.5016.20211218_1245 -acceptLicense -repositories /mnt/software/IBM/WAS/8.5.5.16-ws-was-ifph42899.zip -installationDirectory /opt/IBM/was5/WebSphere/AppServer -log /opt/IBM/was/logs/was_nd_fix_install.20211223102239.log'",
   "_ansible_item_label": {
       "check_sum": "866C82D13C24189E880C70AF7AE20143851330AD1C090E0DCF687B612BBC8513",
       "file_name": "8.5.5.16-ws-was-ifph42899.zip"
   },
   "rc": 2,
   "invocation": {
       "module_args": {
           "creates": null,
           "executable": null,
           "chdir": "/opt/IBM/was/InstallationManager/eclipse/tools/",
           "strip_empty_ends": true,
           "_raw_params": "\"su - was -c /opt/IBM/was/InstallationManager/eclipse/tools/imcl install 8.5.5.16-WS-WAS-IFPH42899_8.5.5016.20211218_1245 -acceptLicense -repositories /mnt/software/IBM/WAS/8.5.5.16-ws-was-ifph42899.zip -installationDirectory /opt/IBM/was5/WebSphere/AppServer -log /opt/IBM/was/logs/was_nd_fix_install.20211223102239.log\"",
           "removes": null,
           "argv": null,
           "warn": true,
           "_uses_shell": false,
           "stdin_add_newline": true,
           "stdin": null
       }
   },
   "msg": "[Errno 2] A file or directory in the path name does not exist.: b'su - was -c /opt/IBM/was/InstallationManager/eclipse/tools/imcl install 8.5.5.16-WS-WAS-IFPH42899_8.5.5016.20211218_1245 -acceptLicense -repositories /mnt/software/IBM/WAS/8.5.5.16-ws-was-ifph42899.zip -installationDirectory /opt/IBM/was5/WebSphere/AppServer -log /opt/IBM/was/logs/was_nd_fix_install.20211223102239.log': b'su - was -c /opt/IBM/was/InstallationManager/eclipse/tools/imcl install 8.5.5.16-WS-WAS-IFPH42899_8.5.5016.20211218_1245 -acceptLicense -repositories /mnt/software/IBM/WAS/8.5.5.16-ws-was-ifph42899.zip -installationDirectory /opt/IBM/was5/WebSphere/AppServer -log /opt/IBM/was/logs/was_nd_fix_install.20211223102239.log'"
}

作為參數傳遞的命令-c需要su被引用。

看起來它將您的命令字元串視為文件。

我相信如果你改變你的玩法:

command:
 chdir: {{ __iim_install_location }}/eclipse/tools/
 cmd: "su - {{ __was_user }} -c {{ __iim_install_location }}/eclipse/tools/imcl install {{ __product_id }} -acceptLicense -repositories {{ __tmp_dir }}/{{ item.file_name }} -installationDirectory {{ __was_install_location}} -log {{ __log_file }}"
register:      cout
with_items:    "{{ __was_this_files }}"
changed_when:  cout.stdout is defined and ( cout.stdout.find( __version_check ) != -1)

特別在命令前面加上cmd: ,它應該可以工作嗎?

引用自:https://serverfault.com/questions/1088090