Closed andy-imt closed 1 year ago
Hello,
I got the same problem, is someone can look to this problem.
Thanks
I'm running into the same issue. Some debugging points me to the following where it hangs waiting on the self._stdout.readline() on line 421 after receiving the command output:
It should run four commands which are wrapped together in the _wrap_command
function:
echo FPJvOAbODNLrUBDNwlzdtqUVqn
sudo sudo -H -S -n -u root /bin/sh -c 'echo BECOME-SUCCESS-mjvhieztmhqnhbcfiprxpidwfjxyvqzj ; /usr/bin/python3 /home/ssm-user/.ansible/tmp/ansible-tmp-1661540567.1878705-101559-269564787724829/AnsiballZ_ping.py'
echo $'\n'$?
echo iXsDFJCFrsWXYtdqfofbGhMbzm
Then it provides to output:
EXEC stdout line: FPJvOAbODNLrUBDNwlzdtqUVqn
EXEC stdout line:
EXEC stdout line: {"ping": "pong", "invocation": {"module_args": {"data": "pong"}}}
What it should be:
EXEC stdout line: FPJvOAbODNLrUBDNwlzdtqUVqn
EXEC stdout line:
EXEC stdout line: {"ping": "pong", "invocation": {"module_args": {"data": "pong"}}}
EXEC stdout line:
EXEC stdout line: 0
EXEC stdout line: iXsDFJCFrsWXYtdqfofbGhMbzm
POST_PROCESS:
{"ping": "pong", "invocation": {"module_args": {"data": "pong"}}}
0
I also have the same issue that I need to provide the Python interpreter, this might be linked to each other because the query result is working:
echo PLATFORM; uname; echo FOUND; command -v 'python3.10'; command -v 'python3.9'; command -v 'python3.8'; command -v 'python3.7'; command -v 'python3.6'; command -v 'python3.5'; command -v '/usr/bin/python3'; command -v '/usr/libexec/platform-python'; command -v 'python2.7'; command -v 'python2.6'; command -v '/usr/bin/python'; command -v 'python'; echo ENDFOUND
POST_PROCESS:
PLATFORM
Linux
FOUND
/usr/bin/python3.10
/usr/bin/python3
ENDFOUND
Unfortunately my Python knowledge isn't enough to further debug and find a solution.
Experiencing the exact same issue. Is there any workaround available?
Experiencing the same issue on amazonlinux
<i-0f7a67efa9c5edae5> SSM CONNECTION ID: gl_gitlab_traefik-06221e159cef6ebda
<i-0f7a67efa9c5edae5> EXEC echo ~
<i-0f7a67efa9c5edae5> (0, '/home/ssm-user\r\r', '')
<i-0f7a67efa9c5edae5> EXEC ( umask 77 && mkdir -p "` echo /home/ssm-user/.ansible/tmp `"&& mkdir "` echo /home/ssm-user/.ansible/tmp/ansible-tmp-1666267435.5919795-7743-117523018265205 `" && echo ansible-tmp-1
666267435.5919795-7743-117523018265205="` echo /home/ssm-user/.ansible/tmp/ansible-tmp-1666267435.5919795-7743-117523018265205 `" )
<i-0f7a67efa9c5edae5> (0, 'ansible-tmp-1666267435.5919795-7743-117523018265205=/home/ssm-user/.ansible/tmp/ansible-tmp-1666267435.5919795-7743-117523018265205\r\r', '')
Using module file /usr/lib/python3/dist-packages/ansible/modules/setup.py
<i-0f7a67efa9c5edae5> PUT /root/.ansible/tmp/ansible-local-774056h3q49o/tmpj0326k_f TO /home/ssm-user/.ansible/tmp/ansible-tmp-1666267435.5919795-7743-117523018265205/AnsiballZ_setup.py
<i-0f7a67efa9c5edae5> EXEC curl 'https://ansible-ssm-gitlab.s3.amazonaws.com/i-0f7a67efa9c5edae5//home/ssm-user/.ansible/tmp/ansible-tmp-1666267435.5919795-7743-117523018265205/AnsiballZ_setup.py?X-Amz-Algorit
hm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIATJO4GSHEUW7EIKGG%2F20221020%2Fap-southeast-1%2Fs3%2Faws4_request&X-Amz-Date=20221020T120356Z&X-Amz-Expires=3600&X-Amz-SignedHeaders=host&X-Amz-Signature=bca081bf63d6234
339fd966289a572af4a3eb059068f13174d83718674b68ec8' -o '/home/ssm-user/.ansible/tmp/ansible-tmp-1666267435.5919795-7743-117523018265205/AnsiballZ_setup.py'
<i-0f7a67efa9c5edae5> (0, ' % Total % Received % Xferd Average Speed Time Time Time Current\r\r\n Dload Upload Total Spent Left Speed\r\r\n\r 0 0
0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0\r 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0\r100 472 0 472 0 0 550 0 --:--:-- --:--:
-- --:--:-- 550\r\r', '')
<i-0f7a67efa9c5edae5> (0, ' % Total % Received % Xferd Average Speed Time Time Time Current\r\r\n Dload Upload Total Spent Left Speed\r\r\n\r 0 0
0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0\r 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0\r100 472 0 472 0 0 550 0 --:--:-- --:--:
-- --:--:-- 550\r\r', '')
<i-0f7a67efa9c5edae5> EXEC chmod u+x /home/ssm-user/.ansible/tmp/ansible-tmp-1666267435.5919795-7743-117523018265205/ /home/ssm-user/.ansible/tmp/ansible-tmp-1666267435.5919795-7743-117523018265205/AnsiballZ_s
etup.py
<i-0f7a67efa9c5edae5> (0, '\r', '')
<i-0f7a67efa9c5edae5> EXEC /bin/python3 /home/ssm-user/.ansible/tmp/ansible-tmp-1666267435.5919795-7743-117523018265205/AnsiballZ_setup.py
<i-0f7a67efa9c5edae5> (1, ' File "/home/ssm-user/.ansible/tmp/ansible-tmp-1666267435.5919795-7743-117523018265205/AnsiballZ_setup.py", line 1\r\r\n <?xml version="1.0" encoding="UTF-8"?>\r\r\n ^\r\r\nSy
ntaxError: invalid syntax\r\r', '')
<i-0f7a67efa9c5edae5> EXEC rm -f -r /home/ssm-user/.ansible/tmp/ansible-tmp-1666267435.5919795-7743-117523018265205/ > /dev/null 2>&1
<i-0f7a67efa9c5edae5> (0, '\r', '')
<i-0f7a67efa9c5edae5> CLOSING SSM CONNECTION TO: i-0f7a67efa9c5edae5
fatal: [my-instance]: FAILED! => {
"ansible_facts": {},
"changed": false,
"failed_modules": {
"ansible.legacy.setup": {
"failed": true,
"module_stderr": "",
"module_stdout": " File \"/home/ssm-user/.ansible/tmp/ansible-tmp-1666267435.5919795-7743-117523018265205/AnsiballZ_setup.py\", line 1\r\r\n <?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\r\n
^\r\r\nSyntaxError: invalid syntax\r\r",
"msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
"rc": 1
}
},
"msg": "The following modules failed to execute: ansible.legacy.setup\n"
}
I am now on the following versions, and I no longer experience the problem:
Collection Version
----------------------------- -------
amazon.aws 3.5.0
community.aws 3.6.0
The issues seems to be on line 466 of aws_ssm.py.
In Dash (which is symlinked as /bin/sh), an echo $'\n'$?
, returns
$
0
While Bash returns
0
Same problem here, did some debugging between an instance running Ubuntu 22.94 minimal (default shell is dash) and another one that is working and use Amazon Linux 2.
What I see is that on Ubuntu the command itself is parsed instead of it results, comparing the outputs
Amazon Linux 2
<i-0846ef408bafd44b1> POST_PROCESS: > ansible-tmp-1668587955.2343445-102-113985281649023=/tmp/.ansible-ssm/ansible-tmp-1668587955.2343445-102-113985281649023
0
<i-0846ef408bafd44b1> (0, '> ansible-tmp-1668587955.2343445-102-113985281649023=/tmp/.ansible-ssm/ansible-tmp-1668587955.2343445-102-113985281649023\r\r', '')
Ubuntu 22.04
<i-0845d1adbe853d3e0> POST_PROCESS: ( umask 77 && mkdir -p "` echo /tmp/.ansible-ssm `"&& mkdir -p "` echo /tmp/.ansible-ssm/ansible-tmp-1668533193.4742794-568-272265113538326 `" && echo ansible-tmp-1668533193.4742794-568-272265113538326="` echo /tmp/.ansible-ssm/ansible-tmp-1668533193.4742794-568-272265113538326 `" )
echo $'\n'$?
<i-0845d1adbe853d3e0> ssm_retry: attempt: 0, caught exception(invalid literal for int() with base 10: "echo $'\\n'$?") from cmd (( umask 77 && mkdir -p "` echo /tmp/.ansible-ssm `"&& mkdir -p "` echo /tmp/.ansible-ssm/ansible-tmp-1668533193.4742794-568-272265113538326 `" && echo ansible-tmp-1668533193.4742794-568-272265113538326="` echo /tmp/.ansible-ssm/ansible-tmp-1668533193.4742794-568-272265113538326 `" )...), pausing for 0 seconds
I still do not know why, but writing the command all on a single line works, so if you want a work around apply this patch, I am going to open a PR too
index 3734d64c..a558f47c 100644
--- a/plugins/connection/aws_ssm.py
+++ b/plugins/connection/aws_ssm.py
@@ -463,7 +463,7 @@ class Connection(ConnectionBase):
else:
if sudoable:
cmd = "sudo " + cmd
- cmd = "echo " + mark_start + "\n" + cmd + "\necho $'\\n'$?\n" + "echo " + mark_end + "\n"
+ cmd = " echo " + mark_start + "; " + cmd + "; echo $'\\n'$?; " + " echo " + mark_end + ";\n"
display.vvvv(u"_wrap_command: '{0}'".format(to_text(cmd)), host=self.host)
return cmd
+1 patch works for me..
Summary
Using the aws_ssm connection to provision a Ubuntu 22.04 Jammy target machine fails presumably due to unexpected characters in the output that it receives (see examples below).
Issue Type
Bug Report
Component Name
aws_ssm
Ansible Version
Collection Versions
AWS SDK versions
Configuration
OS / Environment
Ubuntu 22.04 LTS
Steps to Reproduce
Set SSM Linux shell profile to
/bin/bash
in order to work around incompatibility with/bin/dash
, which exists for Ubuntu 20.04 LTS.Run the configuration provided above
Expected Results
/tmp/foo
is createdActual Results
AnsiballZ_setup.py
script hangs waiting for output. However, investigating on the target machine, the script did indeed complete running, and is able to run successfully.I suspect the issue has to do with the strange control characters in the output, but I am unclear as to the source of them. The machine image is a minimal Ubuntu install, and if I switch back to a 20.04 image instead of 22.04, everything works properly.
Code of Conduct