Score:0

ansible [Errno 2] A file or directory in the path name does not exist

cn flag

I am executing through an ansible tower the following code:

 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)

I receive the following error. I validate and all the paths exist in the remote host.

{
    "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'"
}
Score:0
cn flag

Following all the replies and recommendations I ended up with the following code working:

- 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)
´´´
Score:0
cn flag

It looks like it's treating your command string as a file.

I believe if you change your play to this:

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)

Specifically prefixing the command with cmd: , it should work?

João Pedro Alexandre avatar
cn flag
Thanks, I will try it.
João Pedro Alexandre avatar
cn flag
Something is wrong with that sintaxe. Now I have the following: { "reason": "We were unable to read either as JSON nor YAML, these are the errors we got from each: JSON: No JSON object could be decoded\n\nSyntax Error while loading YAML.\n mapping values are not allowed in this context\n\nThe error appears to be in .../project/roles/was-install-ifix/tasks/install_ifix.yml': line 5, column 8, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n chdir={{ __iim_install_location }}/eclipse/tools/\n
João Pedro Alexandre avatar
cn flag
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 }} We could be wrong, but this one looks like it might be an issue with\nmissing quotes. Always quote template expression brackets when they\nstart a value. For instance:\n\n with_items:\n - {{ foo }}\n\nShould be written as:\n\n with_items:\n - \"{{ foo }}\"\n" }
cn flag
Ah, wrap the argument to `chdir:` in double quotes. But not escaped ones.
Score:0
jp flag

The command passed as parameter -c of su needs to be quoted.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.