Can lock_timeout be applied to a role that uses package module?

If I’m calling the role newrelic.newrelic-infra that uses the package module, is there a way to set or override lock_timeout’s default value of 0 ?
Can you suggest another solution than forking the role, rewriting the task in an OS dependent way using the yum module and setting lock_timeout ?

I have a simple playbook below to setup a web application firewall. I’m using Amazon Linux 2 (4.14.123-111.109.amzn2.x86_64) with python (v2.7.14) that has installed Ansible (v2.8.1) via pip. Packer (v1.4.1) builds of AMI’s thru ansible_local fail with

`
amazon-ebs: TASK [roles/newrelic.newrelic-infra : install agent] ***************************
amazon-ebs: fatal: [127.0.0.1]: FAILED! => {“changed”: false, “msg”: “yum lockfile is held by another process”}

`

By using module_defaults in a play, you can impact all uses of an underlying module.

This can be done for yum, even if using the package module.

https://docs.ansible.com/ansible/latest/user_guide/playbooks_module_defaults.html

There is however a bug in Ansible 2.8 that prevents this from working right now, but a backport PR is waiting to be merged:

https://github.com/ansible/ansible/pull/56400

Thanks for such a quick response. I did find your comment referenced this thread and tried to apply the following in my playbook’s defaults/main.yml.

module_defaults:
yum:
lock_timeout: 30

Letting me know there’s a bug in 2.8 explains why that didn’t work. Changing my build script to:

sudo pip install paramiko git+https://github.com/ansible/ansible.git@devel

Allows the newrelic.newrelic-infra role to install.

The module_defaults attribute only can be used at the play, block, and task level. You cannot add it to a roles defaults.