# Import\_role and module\_defaults

**URL:** <https://forum.ansible.com/t/import-role-and-module-defaults/4277>\
**Category:** Get Help\
**Created:** [March 8, 2024, 8:02pm UTC](https://forum.ansible.com/t/import-role-and-module-defaults/4277 "2024-03-08T20:02:33Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![DengelFred](https://avatars.discourse-cdn.com/v4/letter/d/87869e/32.png) [@DengelFred](https://forum.ansible.com/u/DengelFred)\
**Post date:** [March 8, 2024, 8:02pm UTC](https://forum.ansible.com/t/import-role-and-module-defaults/4277/1 "2024-03-08T20:02:33Z")

</div>

Hello,  
I currently learn ansible and write a few roles for handling a proxmox cluster.  
Each role uses several proxmox modules and each module needs the login data.

therefore I tried to create a role “prox\_common” with the module\_defaults in it:

```auto
# prox_common/tasks/main.yml:

- name: Define proxmox module defaults
  meta: noop

  module_defaults:
    community.general.proxmox_vm_info:
      api_host: "{{ hostvars['pve1']['ansible_host'] }}"
      api_user: "{{ hostvars['pve1']['proxmox_api_user'] }}"
      api_token_id: "{{ hostvars['pve1']['proxmox_api_token_id'] }}"
      api_token_secret: "{{ hostvars['pve1']['proxmox_api_token_secret'] }}"
      node: "{{ hostvars['pve1']['inventory_hostname_short'] }}"

  community.general.proxmox_kvm:
      api_host: "{{ hostvars['pve1']['ansible_host'] }}"
      api_user: "{{ hostvars['pve1']['proxmox_api_user'] }}"
      api_token_id: "{{ hostvars['pve1']['proxmox_api_token_id'] }}"
      api_token_secret: "{{ hostvars['pve1']['proxmox_api_token_secret'] }}"
      node: "{{ hostvars['pve1']['inventory_hostname_short'] }}"

```

I import that role into another role, but unfortunately the default values are not recocnized:

```auto
# prox_create_vm/tasks/main.yml

- import_role:
    name: prox_common

- name: Check status of VM
  delegate_to: pve1
  community.general.proxmox_vm_info:
    vmid: '{{ vm_id }}'
    config: current
  register: proxmox_vms

```

I get the Error: “missing required arguments: api\_host, api\_user”

How can I achive that I have the logindata only at one place?

Thanks a lot 🙂

Thomas

---

<div class="post-metadata">

**Author:** ![akira6592](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/akira6592/32/222_2.png) [@akira6592](https://forum.ansible.com/u/akira6592)\
**Post date:** [March 9, 2024, 2:31am UTC](https://forum.ansible.com/t/import-role-and-module-defaults/4277/2 "2024-03-09T02:31:13Z")

</div>

@DengelFred Hi.

How about specifying module\_defaults at play level not task level?

```auto
- hosts: pve1
  module_defaults:
    community.general.proxmox_vm_info:
      api_host: "{{ ansible_host }}"
      api_user: "{{ proxmox_api_user }}"
      api_token_id: "{{ proxmox_api_token_id }}"
      api_token_secret: "{{ proxmox_api_token_secret }}"
      node: "{{ inventory_hostname_short }}"

  tasks:
    - name: Import prox_create_vm
      ansible.builtin.import_role:
        name: prox_create_vm

```

---

<div class="post-metadata">

**Author:** ![DengelFred](https://avatars.discourse-cdn.com/v4/letter/d/87869e/32.png) [@DengelFred](https://forum.ansible.com/u/DengelFred)\
**Post date:** [March 9, 2024, 11:01am UTC](https://forum.ansible.com/t/import-role-and-module-defaults/4277/3 "2024-03-09T11:01:11Z")

</div>

… because I don’t want the same block in each playbook. 😉  
Unfortunately it’s not only a single module for handling a proxmox cluster, the functionality is distributed accross several modules and each module needs the same defaults…

---

<div class="post-metadata">

**Author:** ![akira6592](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/akira6592/32/222_2.png) [@akira6592](https://forum.ansible.com/u/akira6592)\
**Post date:** [March 9, 2024, 11:43am UTC](https://forum.ansible.com/t/import-role-and-module-defaults/4277/4 "2024-03-09T11:43:41Z")

</div>

Unfortunately perhaps the current version does not allow for it.

Instead, I submitted a pull request to allow using [module default group](https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_module_defaults.html#module-defaults-groups) for `community.general.proxmox_*` modules.

[https://github.com/ansible-collections/community.general/pull/8074](https://github.com/ansible-collections/community.general/pull/8074)

---

<div class="post-metadata">

**Author:** ![felixfontein](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/felixfontein/32/7530_2.png) [@felixfontein](https://forum.ansible.com/u/felixfontein)\
**Post date:** [March 9, 2024, 11:43am UTC](https://forum.ansible.com/t/import-role-and-module-defaults/4277/5 "2024-03-09T11:43:48Z")

</div>

There’s currently a plan to move the proxmox modules from community.general to a separate collection (community.proxmox). That collection will also have a module default group that should solve this problem 🙂

---

<div class="post-metadata">

**Author:** ![felixfontein](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/felixfontein/32/7530_2.png) [@felixfontein](https://forum.ansible.com/u/felixfontein)\
**Post date:** [March 9, 2024, 11:50am UTC](https://forum.ansible.com/t/import-role-and-module-defaults/4277/6 "2024-03-09T11:50:17Z")

</div>

CC [@proxmox-collection](https://forum.ansible.com/groups/proxmox-collection)

---

<div class="post-metadata">

**Author:** ![akira6592](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/akira6592/32/222_2.png) [@akira6592](https://forum.ansible.com/u/akira6592)\
**Post date:** [March 9, 2024, 11:50am UTC](https://forum.ansible.com/t/import-role-and-module-defaults/4277/7 "2024-03-09T11:50:18Z")

</div>

Due to the above reasons [my PR](https://github.com/ansible-collections/community.general/pull/8074) will not be merged.

Wait for `community.proxmox` collectionto be released 😀

---

<div class="post-metadata">

**Author:** ![DengelFred](https://avatars.discourse-cdn.com/v4/letter/d/87869e/32.png) [@DengelFred](https://forum.ansible.com/u/DengelFred)\
**Post date:** [March 9, 2024, 12:02pm UTC](https://forum.ansible.com/t/import-role-and-module-defaults/4277/8 "2024-03-09T12:02:57Z")

</div>

ok, then I will wait for the release.

Thanks a lot!

---

<div class="post-metadata">

**Author:** ![akira6592](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/akira6592/32/222_2.png) [@akira6592](https://forum.ansible.com/u/akira6592)\
**Post date:** [March 9, 2024, 12:06pm UTC](https://forum.ansible.com/t/import-role-and-module-defaults/4277/9 "2024-03-09T12:06:45Z")

</div>

@DengelFred

Then, how about using environment variables?

```yaml
- hosts: proxmox
  environment:
    PROXMOX_HOST: proxmoxhost
    PROXMOX_USER: user
    PROXMOX_PASSWORD: passowrd

  tasks:
    - name: Gather VM Info
      community.general.proxmox_vm_info:
        type: qemu
        node: node01

    - name: List existing nodes
      community.general.proxmox_node_info:
      register: proxmox_nodes

```

---

<div class="post-metadata">

**Author:** ![DengelFred](https://avatars.discourse-cdn.com/v4/letter/d/87869e/32.png) [@DengelFred](https://forum.ansible.com/u/DengelFred)\
**Post date:** [March 9, 2024, 12:42pm UTC](https://forum.ansible.com/t/import-role-and-module-defaults/4277/10 "2024-03-09T12:42:43Z")

</div>

Thanks for the hint, but it seems that not all proxmox modules support PROXMOX\_TOKEN\_ID and PROXMOX\_TOKEN\_SECRET

---

<div class="post-metadata">

**Author:** ![akira6592](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/akira6592/32/222_2.png) [@akira6592](https://forum.ansible.com/u/akira6592)\
**Post date:** [March 9, 2024, 1:00pm UTC](https://forum.ansible.com/t/import-role-and-module-defaults/4277/11 "2024-03-09T13:00:06Z")

</div>

Oops, my bad. Forgot to mention that you are not using passwords.

Unfortunately, `PROXMOX_TOKEN_ID` and `PROXMOX_TOKEN_SECRET` are not supported as you have indicated.

> <https://github.com/ansible-collections/community.general/blob/8.4.0/plugins/module_utils/proxmox.py#L28-L48>

Let’s wait for the release of `community.proxmox`, after all.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [April 8, 2024, 1:00pm UTC](https://forum.ansible.com/t/import-role-and-module-defaults/4277/12 "2024-04-08T13:00:53Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
