Closed nmoseman closed 9 months ago
We just ran into this issue here. It seems that Amazon Linux outputs colorized text when Ansible runs any remote shell commands which causes parsing of the result to fail. Our solution was to not use aws_ssm connection - instead we setup SSH to make connections through Session Manager: https://docs.aws.amazon.com/systems-manager/latest/userguide/session-manager-getting-started-enable-ssh-connections.html
I was facing this same issue with hosts running both Ubuntu 22.04 and Amazon Linux 2023, and I was finally able to trace the extra output to a root cause. This is due to newer versions of Bash/readline turning on the option enable-bracketed-paste
by default (more details here).
I have a patch that will disable this option (will send a PR later today), which allows ansible -m ping
to work on several hosts I have access to, including Ubuntu 18.04, Amazon Linux 2023, and Ubuntu 22.04.
https://github.com/ansible-collections/community.aws/pull/1839
Confirmed it's working with Amazon Linux
I've ended up having the same issue switching from amazon Linux 2 to amazon Linux 2023, my error was:
service-use1-bh | UNREACHABLE! => {
"changed": false,
"msg": "Failed to create temporary directory. In some cases, you may have been able to authenticate and did not have permissions on the target directory. Consider changing the remote tmp path in ansible.cfg to a path rooted in \"/tmp\", for more error information use -vvv. Failed command was: ( umask 77 && mkdir -p \"` echo \u001b[?2004h\u001b[?2004l/.ansible/tmp `\"&& mkdir \"` echo \u001b[?2004h\u001b[?2004l/.ansible/tmp/ansible-tmp-1694091988.5261781-5952-41494157774678 `\" && echo ansible-tmp-1694091988.5261781-5952-41494157774678=\"` echo \u001b[?2004h\u001b[?2004l/.ansible/tmp/ansible-tmp-1694091988.5261781-5952-41494157774678 `\" ), exited with result 1, stdout output: \u001b[?2004h\u001b[?2004l\r\r\r\nmkdir: cannot create directory ‘2004h2004l’: Permission denied\r\r\n\u001b[?2004h\u001b[?2004l\r\r\r",
"unreachable": true
}
https://github.com/ansible-collections/community.aws/pull/1839 fixes it, but it's taking ages to be merged for unknown reasons. In the meantime I've set set enable-bracketed-paste off
into /etc/inputrc
which is, needless to say, not a fix at all since you need to configure all servers this way, which is exactly what ansible is meant to do. In my case was just one so for now it's sorted, thanks to @dennisjlee !
@tremble Hi, you released v7.1.0 and its release note mentioned this issue fixed, but it is not.
@Hokwang #1839 now results in the integration tests passing, which they previously didn't. This includes tests running against the latest Amazon Linux AMIs as exposed by Amazon as the SSM Parameter /aws/service/ami-amazon-linux-latest/amzn2-ami-hvm-x86_64-gp2
.
As such I can only respond with "Unable to Reproduce" at this time
It would be helpful if you could provide details of exactly what error you're seeing against which AMI. I would strongly recommend opening a new issue (comments on closed issues are very easy to overlook), with much more detail than "still doesn't work for me".
Summary
I had good luck with the aws_ssm plugin until attempting to use it against the latest Amazon Linux AMI. Simple commands that work well with a CentOS 7 host fails when trying to run them against AMI. It appears to be something to do with interpreting shell output.
A 'raw' command like this works fine:
However when running the equivalent 'command' module it fails for Amazon Linux, but works on CentOS 7.
Versus CentOS 7:
From '-vvvv' output I see things like this:
That's a failure to find the python version. Versus:
Where it didn't complain and seems to be successful. Notice the additional "x1b[?2004h\x1b[?2004" strings in the output.
I see the similar string in other problems, like "Warning: Failed to open the file 2004h2004l/AnsiballZ_command.py"
Note that if I set the python interpreter it will remove the warning, but it will still error out on the "Failed to open the file 2004h2004l/AnsiballZ_command.py: No such file Warning: or directory"
Tried this with community.aws collection versions 4.5.0, 5.2.0, and 5.3.0 and the errors is the same every time. Also tried a few different amazon.aws collection versions and had the same error.
These examples are taken from a Mac running python 3.11.2 and ansible 2.14.2, but the same errors occured in a Linux-based Execution Environment for AWX running in EKS.
Issue Type
Bug Report
Component Name
aws_ssm connection
Ansible Version
Collection Versions
AWS SDK versions
Configuration
OS / Environment
Darwin ENG-NMOSEMAN-MB 22.3.0 Darwin Kernel Version 22.3.0: Mon Jan 30 20:42:11 PST 2023; root:xnu-8792.81.3~2/RELEASE_X86_64 x86_64 i386 Darwin
and
modified version of quay.io/ansible/awx-ee:latest to include community.aws, and ssm stuff.
Steps to Reproduce
Expected Results
Actual Results
Code of Conduct