I’m running some sudo commands via the command module. In one of the commands, when I use a variable to specify the path to a script there is an error during the variable substitution and the command fails. In some commands, the variable substitution works while in one it doesn’t. I have not determined what is different between the examples that work and those that do not.
Here is more detail:
When I run a playbook containing the following two commands
command: “sudo -u wasadmin {{ was_install_dir }}/profiles/{{ was_profile_name }}/bin/stopServer.sh {{ was_server_name }}”
command: “sudo -u wasadmin /opt/IBM/WebSphere/UpdateInstaller/update.sh -silent -options {{ was_maintenance_response_file }}”
… both commands run successfully on the remote host. The output of the playbook shows that the correct commands are run:
TASK: [worklight_maintenance | Stop the application server] *******************
<remote.host.name> REMOTE_MODULE command sudo -u wasadmin /opt/IBM/WebSphere/AppServer/profiles/AppSrv01/bin/stopServer.sh server1
TASK: [worklight_maintenance | Apply WAS maintenance] *************************
<remote.host.name> REMOTE_MODULE command sudo -u wasadmin /opt/IBM/WebSphere/UpdateInstaller/update.sh -silent -options /opt/build/maintenance/was.maintenance.rsp
But when I change the second command to also use a variable in place of the full path to the script, like so (see highlighed change):
command: “sudo -u wasadmin {{ was_install_dir }}/profiles/{{ was_profile_name }}/bin/stopServer.sh {{ was_server_name }}”
command: “sudo -u wasadmin {{ was_updi_update_sh }} -silent -options {{ was_maintenance_response_file }}”
… the second command doesn’t run successfully. In the playbook output we see that the substitution of the variable {{ was_updi_update_sh }} has gone terribly wrong as shown by the highlighted section.
<ecwlapp1qa4.hhgregg.com> REMOTE_MODULE command sudo -u wasadmin /opt/IBM/WebSphere/AppServer/profiles/AppSrv01/bin/stopServer.sh server1
<ecwlapp1qa4.hhgregg.com> REMOTE_MODULE command sudo -u wasadmin {‘invocation’: {‘module_name’: u’stat’, ‘module_complex_args’: {}, ‘module_args’: u’path=/opt/IBM/WebSphere/UpdateInstaller/update.sh’}, ‘stat’: {‘uid’: 522, ‘exists’: True, ‘woth’: False, ‘mtime’: 1442612966, ‘inode’: 5931018, ‘isgid’: False, ‘size’: 1286, ‘isuid’: False, ‘isreg’: True, ‘pw_name’: ‘wasadmin’, ‘gid’: 522, ‘ischr’: False, ‘wusr’: True, ‘xoth’: True, ‘rusr’: True, ‘nlink’: 1, ‘issock’: False, ‘rgrp’: True, ‘gr_name’: ‘wasadmin’, ‘path’: ‘/opt/IBM/WebSphere/UpdateInstaller/update.sh’, ‘xusr’: True, ‘atime’: 1456861468, ‘md5’: ‘142ed49388e43e9f2a7174e9f0974809’, ‘isdir’: False, ‘ctime’: 1442612966, ‘isblk’: False, ‘wgrp’: False, ‘xgrp’: True, ‘dev’: 64773, ‘roth’: True, ‘isfifo’: False, ‘mode’: ‘0755’, ‘checksum’: ‘3f15c2e57403d7d38d5ab5e1111fbc6b3f9c62e5’, ‘islnk’: False}, ‘changed’: False} -silent -options /opt/build/maintenance/was.maintenance.rsp
The variables are all defined in the same way. They are defined in a file like so:
`
-sh-4.1$ cat roles/worklight_maintenance/vars/worklight.yml