Skip to content

Agent installation fails on aws amzn2 #406

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
msiebeneicher opened this issue Dec 23, 2021 · 2 comments · Fixed by #412
Closed

Agent installation fails on aws amzn2 #406

msiebeneicher opened this issue Dec 23, 2021 · 2 comments · Fixed by #412

Comments

@msiebeneicher
Copy link

Hi,

we are using the datadog.datadog role from ansible galaxy now for a couple of time.
Since the last agent version 7.32.4 (how it looks like) our packer build is failing with the following error message:

TASK [datadog.datadog : Fail early if Python 3 is used on CentOS / RHEL < 8] ***
    amz-ami: fatal: [default]: FAILED! => {"changed": false, "msg": "The installation of the Agent on CentOS / RHEL versions < 8 requires the 'yum' module, which is not compatible with Python 3. To run this role, use a Python 2 interpreter on hosts running CentOS / RHEL < 8."}

This error happen on the latest aws ami amzn2-ami-hvm-2.0.20211201.0-x86_64-ebs (ami-01826408c6676f97e) and also on the previous version (ami-0d455065dfd31a3cd) which we already successfully used in the past.

As a workaround we tried successfully to install the agent by the official shell installer on the same ec2 instance:
DD_AGENT_MAJOR_VERSION=7 DD_API_KEY=<KEy> DD_SITE="datadoghq.eu" bash -c "$(curl -L https://s3.amazonaws.com/dd-agent/scripts/install_script.sh)"

I also tried the workaround described in your docs under https://docs.datadoghq.com/agent/basic_agent_usage/ansible/ which also was not working in our case because thednf and the python3-dnf packages are not available in the default aws repositories. If I use the optiondatadog_ignore_old_centos_python3_error: true i get the following error message:

TASK [datadog.datadog : Install latest datadog-agent package (dnf)] ************
    amz-ami: fatal: [default]: FAILED! => {"changed": false, "msg": "Could not import the dnf python module using /usr/bin/python3.7 (3.7.10 (default, Jun  3 2021, 00:02:01) [GCC 7.3.1 20180712 (Red Hat 7.3.1-13)]). Please install `python3-dnf` or `python2-dnf` package or ensure you have specified the correct ansible_python_interpreter. (attempted ['/usr/libexec/platform-python', '/usr/bin/python3', '/usr/bin/python2', '/usr/bin/python'])", "results": []}

Any ideas or suggestions to handle this issue or why this issue is popping up now?

Here my used version:

  • ansible [core 2.12.1]
  • packer 1.7.8

datadog.datadog role version:

  • 4.12.0
  • 4.11.0

aws amis:

  • "Name": "amzn2-ami-hvm-2.0.20211201.0-x86_64-ebs",
    "ImageId": "ami-01826408c6676f97e",
    "CreationDate": "2021-12-01T19:55:07.000Z"

  • "Name": "amzn2-ami-hvm-2.0.20211005.0-x86_64-ebs",
    "ImageId": "ami-0d455065dfd31a3cd",
    "CreationDate": "2021-10-12T14:12:46.000Z"

@moleskin-smile
Copy link
Contributor

moleskin-smile commented Jan 18, 2022

I have the same problem on Amazon Linux 2.

So the problematic change is this one: #301.

I think it is based on assumptions that are not always true. It wants to use dnf intead of yum if ansible_facts.python.version.major >= 3 – I don't think this is the right thing to do. ansible_facts.python.version.major is just a Python version detected by Ansible. It doesn't mean it's a default Python installation, nor allows to conclude about package manager being used. We run Ansible with Python 3 on Amazon Linux 2 without problems for years.

I think the right fact to use is ansible_pkg_mgr.

Side note: the yum Ansible builtin supports dnf, see:

This module supports yum (as it always has), this is known as yum3/YUM3/yum-deprecated by upstream yum developers. As of Ansible 2.7+, this module also supports YUM4, which is the "new yum" and it has an dnf backend.
By default, this module will select the backend based on the ansible_pkg_mgr fact.

So maybe even no changes are required. And the original issue (#298), that reported this, mentions documentation entry about yum module not being supported on Python 3. But it is – for years. Maybe not via native bindings, but it works. And regarding dnf support – AFAIK there's compatibility layer that allows using yum command on a dnf system.

moleskin-smile added a commit to moleskin-smile/ansible-datadog that referenced this issue Jan 21, 2022
Don't use `python.version.major >= 3` condition to select `dnf` instead
of `yum`, because it breaks Python 3 on Amazon Linux 2 setups, where
`yum` is still used. Use `ansible_pkg_mgr` fact directly instead.

Fixes: DataDog#406.
moleskin-smile added a commit to moleskin-smile/ansible-datadog that referenced this issue Jan 21, 2022
Don't use `python.version.major >= 3` condition to select `dnf` instead
of `yum`, because it breaks Python 3 on Amazon Linux 2 setups, where
`yum` is still used. Use `ansible_pkg_mgr` fact directly instead.

Remove an explicit fail that's too defensive.

Fixes: DataDog#406.
@moleskin-smile
Copy link
Contributor

@msiebeneicher: could you please test your setup with changes from #412? Thanks!

bkabrda pushed a commit that referenced this issue Feb 1, 2022
* Fix provisioning on Python 3 / Amazon Linux 2

Don't use `python.version.major >= 3` condition to select `dnf` instead
of `yum`, because it breaks Python 3 on Amazon Linux 2 setups, where
`yum` is still used. Use `ansible_pkg_mgr` fact directly instead.

Fixes: #406.

* Add manual testing on Centos 8 and Amazon Linux 2

1. Extend manual tests setup to include more operating systems – modern
   RedHat-style one (Centos 8) that uses dnf, legacy RedHat-style one
   which uses yum (Amazon Linux 2). Keep Ubuntu as a default one.
2. Run Ansible on provisioned machines automatically. By default all
   playbooks are run. Now there is no need to change current working
   directory to interact with Ansible and Vagrant. There's also no need
   to modify inventory file if ports change. There're also no problems
   with SSH known hosts anymore.
3. Update `readme.md`.
4. Git ignore `.vagrant`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants