我正在通过 ansible tower 执行以下代码:
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'"
}
答案1
作为参数传递的命令-c
需要su
用引号引起来。
答案2
它看起来正在将您的命令字符串视为一个文件。
我相信如果你把你的游戏方式改变成这样:
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:
,它应该可以工作吗?
答案3
按照所有的回复和建议,我最终得到了以下代码:
- name: Update IBM WAS Software
command:
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 }}'"
args:
chdir: "{{ __iim_install_location }}/eclipse/tools/"
register: cout
with_items: "{{ __was_this_files }}"
changed_when: cout.stdout is defined and ( cout.stdout.find( __version_check ) != -1)
´´´