# Azure Dynamic Inventory Issue

**URL:** <https://forum.ansible.com/t/azure-dynamic-inventory-issue/2647>\
**Category:** Get Help\
**Tags:** azure, aws, collections, awx\
**Created:** [November 30, 2023, 6:54am UTC](https://forum.ansible.com/t/azure-dynamic-inventory-issue/2647 "2023-11-30T06:54:46Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![ku1918](https://avatars.discourse-cdn.com/v4/letter/k/278dde/32.png) [@ku1918](https://forum.ansible.com/u/ku1918)\
**Post date:** [November 30, 2023, 6:54am UTC](https://forum.ansible.com/t/azure-dynamic-inventory-issue/2647/1 "2023-11-30T06:54:46Z")

</div>

Hi all,

I would like to get some help.

I have configure the following sync configuration.

```auto
---
keyed_groups:
  - key: tags.Environment
    separator: ""
  - key: powerstate
    separator: ""
  - key: image.offer
    separator: ""
hostnames:
    - name
hostvar_expressions:
    csp: "'azure'"

```

I got 2 issue that I need help with.

1. Azure inventory doesn’t not capture virtual machine in stopped state.
2. Disable host before syncing are override when a new sync trigger. How to prevent the overwrite. I did not tick the “Overwrite”. This behaviour doesn’t happen with AWS plugin. I assume its a Azure RM plugin issue.

Thanks for any help

---

<div class="post-metadata">

**Author:** ![disi](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/disi/32/1138_2.png) [@disi](https://forum.ansible.com/u/disi)\
**Post date:** [November 30, 2023, 7:44am UTC](https://forum.ansible.com/t/azure-dynamic-inventory-issue/2647/2 "2023-11-30T07:44:48Z")

</div>

Good morning, I use this for Azure:  
Enabled Variable: provisioning\_state  
Enabled Value: succeeded  
This enables also deallocated machines, as long as they have been imaged.

I do not manually disable or enable hosts. I think the whole idea of this variable is to have this detected automatically.  
Instead I add a connection detection in front of every role together with end\_host if not reachable for those.

Something like

```auto
- name: Check connection
  ansible.builtin.ping:
  register: _ping_result
- name: Remove unwanted hosts from play_hosts
  ansible.builtin.meta: end_host
  when: _ping_result.unreachable is defined

```

---

<div class="post-metadata">

**Author:** ![ku1918](https://avatars.discourse-cdn.com/v4/letter/k/278dde/32.png) [@ku1918](https://forum.ansible.com/u/ku1918)\
**Post date:** [November 30, 2023, 8:22am UTC](https://forum.ansible.com/t/azure-dynamic-inventory-issue/2647/3 "2023-11-30T08:22:03Z")

</div>

I see thanks.

Do this consider a failed job template?

---

<div class="post-metadata">

**Author:** ![disi](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/disi/32/1138_2.png) [@disi](https://forum.ansible.com/u/disi)\
**Post date:** [November 30, 2023, 8:32am UTC](https://forum.ansible.com/t/azure-dynamic-inventory-issue/2647/4 "2023-11-30T08:32:28Z")

</div>

If you add an `ignore_errors: true` it would continue.

This is a philosophical question 😃  
Some say: let jobs fail!  
Some say: Do error handling!

I prefer error handling…

---

<div class="post-metadata">

**Author:** ![ku1918](https://avatars.discourse-cdn.com/v4/letter/k/278dde/32.png) [@ku1918](https://forum.ansible.com/u/ku1918)\
**Post date:** [November 30, 2023, 8:39am UTC](https://forum.ansible.com/t/azure-dynamic-inventory-issue/2647/5 "2023-11-30T08:39:50Z")

</div>

In this case , the end\_host only for host that are not reachable right.

Other host that have no issue , those will still continue?

---

<div class="post-metadata">

**Author:** ![disi](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/disi/32/1138_2.png) [@disi](https://forum.ansible.com/u/disi)\
**Post date:** [November 30, 2023, 8:52am UTC](https://forum.ansible.com/t/azure-dynamic-inventory-issue/2647/6 "2023-11-30T08:52:59Z")

</div>

Yes, this is correct.

It will gracefully end the playbook for those hosts, not produce an error.  
[https://docs.ansible.com/ansible/latest/collections/ansible/builtin/meta\_module.html](https://docs.ansible.com/ansible/latest/collections/ansible/builtin/meta_module.html)

---

<div class="post-metadata">

**Author:** ![ku1918](https://avatars.discourse-cdn.com/v4/letter/k/278dde/32.png) [@ku1918](https://forum.ansible.com/u/ku1918)\
**Post date:** [November 30, 2023, 2:32pm UTC](https://forum.ansible.com/t/azure-dynamic-inventory-issue/2647/7 "2023-11-30T14:32:55Z")

</div>

I just try adding provisoning\_state.

Still unable to retrieve stopped(deallocated) virtual machine.

Any idea?

---

<div class="post-metadata">

**Author:** ![ku1918](https://avatars.discourse-cdn.com/v4/letter/k/278dde/32.png) [@ku1918](https://forum.ansible.com/u/ku1918)\
**Post date:** [November 30, 2023, 2:37pm UTC](https://forum.ansible.com/t/azure-dynamic-inventory-issue/2647/8 "2023-11-30T14:37:23Z")

</div>

OK nevermind.

Found out the plugin has a  
**default\_host\_filters**  **Default:** `["powerstate != \"running\"", "provisioning_state != \"succeeded\""]`

That why stopped VM are not showing.

I just need to remove the powerstate

---

<div class="post-metadata">

**Author:** ![disi](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/disi/32/1138_2.png) [@disi](https://forum.ansible.com/u/disi)\
**Post date:** [November 30, 2023, 3:01pm UTC](https://forum.ansible.com/t/azure-dynamic-inventory-issue/2647/9 "2023-11-30T15:01:46Z")

</div>

Sorry, yes.  
I clear all default host filters as well:

```auto
# filters
default_host_filters: []

```

Then add your own stuff here.
