7

AWS' Linux 2 has a facility "Amazon Linux Extras" which provides additional repos for assorted things (nginx, php, mariadb, etc. etc.).

I'm surprised that I can't find an Ansible module(s) for this feature. I found an repo in github for this, but it's empty.

I can work around this by hand crafting yum_repository module tasks. That demands reverse engineering what AWS's CLI command (aka amazon-linux-extras install ...) is doing. Or I could run that command directly, but that of course will trigger a change every time I run the playbook.

Any suggestions?

Ben Hyde
  • 1,503
  • 12
  • 14
  • You could write an Ansible module to support the amazon linux extras package manager. With a little work you might be able to get that accepted into Ansible. – larsks Apr 30 '19 at 16:08

2 Answers2

13

A reasonable work around, until a module shows up for amazon-linux-extras.

- command: amazon-linux-extras install nginx1.12=latest -y
  args:
    creates: /sbin/nginx

The creates arg. is the hack to make commands the task reasonably idempotent.

Ben Hyde
  • 1,503
  • 12
  • 14
  • 2
    While good for a one-off, this is an unsatisfactory way to manage dependencies across what is currently 51 different "extras" topics (requiring filesystem knowledge for each). Among other things, changing the expected version in the command would never update the package! – Joe Atzberger Mar 05 '21 at 19:41
2

Add this to your tasks:

- name: Enable amazon-linux-extras packages
  shell: amazon-linux-extras enable postgresql14

Then you can use yum to manage the package.

Velizar Hristov
  • 662
  • 2
  • 10
  • 23
  • Don't forget to add the ```args: creates: ....``` – Ivailo Bardarov Oct 17 '22 at 15:38
  • @IvailoBardarov What should args:create: look like for this task? – RaGe Nov 17 '22 at 19:46
  • I don't have `args: creates: ...` and my code works perfectly without it. – Velizar Hristov Nov 22 '22 at 06:24
  • 1
    with args creates syntax we specify what files/folders/etc are created with this task. that way if they are found the operation will be marked as green. It is important to have only green tasks on re-run. That we make the tasks idempotent With this you gain speed and it's clear when action is really required – Ivailo Bardarov Nov 22 '22 at 18:51