# module\_defaults not working

**URL:** <https://forum.ansible.com/t/module-defaults-not-working/31951>\
**Category:** Ansible Developer\
**Created:** [January 13, 2020, 4:44am UTC](https://forum.ansible.com/t/module-defaults-not-working/31951 "2020-01-13T04:44:49Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Punit\_Jain](https://avatars.discourse-cdn.com/v4/letter/p/e56c9b/32.png) [@Punit\_Jain](https://forum.ansible.com/u/Punit_Jain)\
**Post date:** [January 13, 2020, 4:44am UTC](https://forum.ansible.com/t/module-defaults-not-working/31951/1 "2020-01-13T04:44:49Z")

</div>

Hi,

I have a playbook which imports custom role and passes required attributes. My requirement is to pass only required attributes and role specify remaining. below is explained in detail.

playbook

---

<div class="post-metadata">

**Author:** ![cassell](https://avatars.discourse-cdn.com/v4/letter/c/ecae2f/32.png) [@cassell](https://forum.ansible.com/u/cassell)\
**Post date:** [January 13, 2020, 6:29am UTC](https://forum.ansible.com/t/module-defaults-not-working/31951/2 "2020-01-13T06:29:45Z")

</div>

> Hi,
> 
> I have a playbook which imports custom role and passes required  
> attributes. My requirement is to pass only required attributes and role  
> specify remaining. below is explained in detail.
> 
> playbook  
> ------------
> 
> ---  
> - hosts: remote  
> gather\_facts: yes  
> tasks:  
> - import\_role: {name: xaas}  
> - name: call action  
> xaasaction:  
> id: "{{id}}"  
> action: "{{action}}"  
> register: output

Your module\_defaults in the role is not valid here. It only takes effect for the task where it is specified. You could add it to the play above to make it effective for this task.

V/r,  
James Cassell

---

<div class="post-metadata">

**Author:** ![Punit\_Jain](https://avatars.discourse-cdn.com/v4/letter/p/e56c9b/32.png) [@Punit\_Jain](https://forum.ansible.com/u/Punit_Jain)\
**Post date:** [January 13, 2020, 7:40am UTC](https://forum.ansible.com/t/module-defaults-not-working/31951/3 "2020-01-13T07:40:09Z")

</div>

Hi James,

My role is being used by multiple other roles and playbooks. This would mean it will require every playbook and role accessing this module, to pass username and password fields which I think should be abstracted and should be taken care by something like module\_defaults and let the playbook and role only pass required attributes which change. Thoughts ?

Regards,  
Punit
