You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/ansible/ansible-manage-azure-dynamic-inventories.md
+69-40Lines changed: 69 additions & 40 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -66,11 +66,20 @@ Ansible can be used to pull inventory information from various sources (includin
66
66
67
67
You can [use tags to organize your Azure resources](https://docs.microsoft.com/azure/azure-resource-manager/resource-group-using-tags#azure-cli) by user-defined categories.
68
68
69
+
### Using Ansible version < 2.8
69
70
Enter the following [az resource tag](/cli/azure/resource?view=azure-cli-latest.md#az-resource-tag) command to tag the virtual machine `ansible-inventory-test-vm1` with the key `nginx`:
70
71
71
72
```azurecli-interactive
72
73
az resource tag --tags nginx --id /subscriptions/<YourAzureSubscriptionID>/resourceGroups/ansible-inventory-test-rg/providers/Microsoft.Compute/virtualMachines/ansible-inventory-test-vm1
73
74
```
75
+
76
+
### Using Ansible version >= 2.8
77
+
Enter the following [az resource tag](/cli/azure/resource?view=azure-cli-latest.md#az-resource-tag) command to tag the virtual machine `ansible-inventory-test-vm1` with the key `Ansible=nginx`:
78
+
79
+
```azurecli-interactive
80
+
az resource tag --tags Ansible=nginx --id /subscriptions/<YourAzureSubscriptionID>/resourceGroups/ansible-inventory-test-rg/providers/Microsoft.Compute/virtualMachines/ansible-inventory-test-vm1
81
+
```
82
+
74
83
## Generate a dynamic inventory
75
84
76
85
Once you have your virtual machines defined (and tagged), it's time to generate the dynamic inventory.
@@ -119,10 +128,14 @@ Starting with Ansible 2.8, Ansible provides an [Azure dynamic-inventory plugin](
119
128
1. The inventory plugin requires a configuration file. The configuration file must end in `azure_rm` and have an extension of either `yml` or `yaml`. For this tutorial example, save the following playbook as `myazure_rm.yml`:
120
129
121
130
```yml
122
-
plugin: azure_rm
123
-
include_vm_resource_groups:
124
-
- ansible-inventory-test-rg
125
-
auth_source: auto
131
+
plugin: azure_rm
132
+
include_vm_resource_groups:
133
+
- ansible-inventory-test-rg
134
+
auth_source: auto
135
+
136
+
keyed_groups:
137
+
- prefix: tag
138
+
key: tags
126
139
```
127
140
128
141
1. Run the following command to ping VMs in the resource group:
@@ -151,33 +164,49 @@ Starting with Ansible 2.8, Ansible provides an [Azure dynamic-inventory plugin](
151
164
```
152
165
153
166
## Enable the VM tag
154
-
Once you've set a tag, you need to "enable" that tag. One way to enable a tag is by exporting the tag to an environment variable `AZURE_TAGS` via the `export` command:
155
167
156
-
```azurecli-interactive
157
-
export AZURE_TAGS=nginx
158
-
```
168
+
### If you're using Ansible < 2.8,
159
169
160
-
- If you're using Ansible < 2.8, run the following command:
170
+
- Once you've set a tag, you need to "enable" that tag. One way to enable a tag is by exporting the tag to an environment variable `AZURE_TAGS` via the `export` command:
0 commit comments