# How to set the description for hosts in a dynamic inventory

**URL:** <https://forum.ansible.com/t/how-to-set-the-description-for-hosts-in-a-dynamic-inventory/36801>\
**Category:** AWX Project\
**Created:** [July 4, 2022, 3:37pm UTC](https://forum.ansible.com/t/how-to-set-the-description-for-hosts-in-a-dynamic-inventory/36801 "2022-07-04T15:37:17Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Andrew\_Mulheirn](https://avatars.discourse-cdn.com/v4/letter/a/7993a0/32.png) [@Andrew\_Mulheirn](https://forum.ansible.com/u/Andrew_Mulheirn)\
**Post date:** [July 4, 2022, 3:37pm UTC](https://forum.ansible.com/t/how-to-set-the-description-for-hosts-in-a-dynamic-inventory/36801/1 "2022-07-04T15:37:17Z")

</div>

Hi,

I’m using a dynamic inventory - python that pulls in hosts from a Google Sheet. It all works well, except that the description always appears as ‘imported’. I can manually edit an imported entry to set the description for each (as you can see in the top line), but would like this to be automatic.

 ![inventory.png](https://us1.discourse-cdn.com/ansible/original/2X/7/7466fed7499d77b45b545466122f083a8c16fbd8.png)

The reason I want this value at the higher level is because the ‘name’ in the first column is a serial number (for uniqueness) and the description is a more human-friendly string.

When I click on a host that shows as ‘imported’ in the description column on the list view, I can see that my description has been put in the extra variables:

 ![inventory2.png](https://us1.discourse-cdn.com/ansible/original/2X/e/ee1559a554f64668351d73a7119b01e4c16fed4b.png)

So I know that there’s a value in there, but it is ending up in the wrong place.  
If I browse the API for host 18, I see this:

 ![inventory3.png](https://us1.discourse-cdn.com/ansible/original/2X/1/1d32acdc2502c6009666418b75d351a00b7ef931.png)

My description has become part of the host\_vars it seems. The description field in the next level up is ‘imported’.

According to the API docs ([https://docs.ansible.com/ansible-tower/latest/html/towerapi/api\_ref.html#/Inventories/Inventories\_inventories\_hosts\_create](https://docs.ansible.com/ansible-tower/latest/html/towerapi/api_ref.html#/Inventories/Inventories_inventories_hosts_create)) the description should be settable and is blank by default. Something is obviously setting it to ‘imported’ but I don’t know what that could be.

It feels like inventory.add\_host method doesn’t allow the setting of a host description. All you can do is inventory.set\_variable which puts the value in the variables list.

If anyone has any ideas, I’d be glad to hear them!

Regards,  
Andy

---

<div class="post-metadata">

**Author:** ![AWX\_Project](https://avatars.discourse-cdn.com/v4/letter/a/eada6e/32.png) [@AWX\_Project](https://forum.ansible.com/u/AWX_Project)\
**Post date:** [July 6, 2022, 7:43pm UTC](https://forum.ansible.com/t/how-to-set-the-description-for-hosts-in-a-dynamic-inventory/36801/2 "2022-07-06T19:43:33Z")

</div>

Hi!

Can you try “\_awx\_description” instead of “description” and see if that correctly adds the description to your imported hosts?

Please see [https://github.com/ansible/awx/pull/6265](https://github.com/ansible/awx/pull/6265)

Let us know if that works for ya, we’ll be sure to get proper documentation around this.

AWX Team

---

<div class="post-metadata">

**Author:** ![Andrew\_Mulheirn](https://avatars.discourse-cdn.com/v4/letter/a/7993a0/32.png) [@Andrew\_Mulheirn](https://forum.ansible.com/u/Andrew_Mulheirn)\
**Post date:** [July 7, 2022, 8:31pm UTC](https://forum.ansible.com/t/how-to-set-the-description-for-hosts-in-a-dynamic-inventory/36801/3 "2022-07-07T20:31:17Z")

</div>

Thanks very much - that looks like exactly what I was after. It isn’t working for me yet though - is this wrong? I’m still getting ‘Imported’ in the description, and \_awx\_description is ending up in the host vars:

# Update Desc

self.inventory.set\_variable(hostname, “\_awx\_description”, descr)

---

<div class="post-metadata">

**Author:** ![AWX\_Project](https://avatars.discourse-cdn.com/v4/letter/a/eada6e/32.png) [@AWX\_Project](https://forum.ansible.com/u/AWX_Project)\
**Post date:** [July 13, 2022, 8:01pm UTC](https://forum.ansible.com/t/how-to-set-the-description-for-hosts-in-a-dynamic-inventory/36801/4 "2022-07-13T20:01:28Z")

</div>

Hi,

Can you let us know which AWX version you are using?

Also, would mind reporting the resulting output when you run your inventory script from the command line? I can’t really tell how your self.inventory.set\_variable call is affecting the end result.

Thanks!

AWX Team

---

<div class="post-metadata">

**Author:** ![Andrew\_Mulheirn](https://avatars.discourse-cdn.com/v4/letter/a/7993a0/32.png) [@Andrew\_Mulheirn](https://forum.ansible.com/u/Andrew_Mulheirn)\
**Post date:** [July 21, 2022, 10:24am UTC](https://forum.ansible.com/t/how-to-set-the-description-for-hosts-in-a-dynamic-inventory/36801/5 "2022-07-21T10:24:35Z")

</div>

Hi there,

Thanks - is this output what you need to see?

Kind regards,  
Andy

ansible-inventory -i inventory/dev-gsheets.yaml --list -vv  
ansible-inventory [core 2.12.4]  
config file = /Users/username/Library/CloudStorage/OneDrive-company/sandbox/ansible-gsheets-inventory/ansible.cfg  
configured module search path = [‘/Users/username/.ansible/plugins/modules’, ‘/usr/share/ansible/plugins/modules’]  
ansible python module location = /Users/username/Library/CloudStorage/OneDrive-company/sandbox/ansible-gsheets-inventory/.venv/lib/python3.8/site-packages/ansible  
ansible collection location = /Users/username/.ansible/collections:/usr/share/ansible/collections  
executable location = /Users/username/sandbox/ansible-gsheets-inventory/.venv/bin/ansible-inventory  
python version = 3.8.2 (default, Dec 21 2020, 15:06:04) [Clang 12.0.0 (clang-1200.0.32.29)]  
jinja version = 3.1.1  
libyaml = True  
Using /Users/username/Library/CloudStorage/OneDrive-company/sandbox/ansible-gsheets-inventory/ansible.cfg as config file  
[gsheets] inventory file: /Users/username/Library/CloudStorage/OneDrive-company/sandbox/ansible-gsheets-inventory/inventory/dev-gsheets.yaml  
[gsheets] reading plugin options  
[gsheets] checking dependencies  
[gsheets] sys path: [‘/Users/username/Library/CloudStorage/OneDrive-company/sandbox/ansible-gsheets-inventory/.venv/bin’, ‘/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python38.zip’, ‘/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8’, ‘/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/lib-dynload’, ‘/Users/username/Library/CloudStorage/OneDrive-company/sandbox/ansible-gsheets-inventory/.venv/lib/python3.8/site-packages’]  
[gsheets] dependencies met  
[gsheets] fetch API token  
[gsheets] opening sheet  
[gsheets] sheet opened: 1GacYZXvmEyL08pnZHsB\_H5uVGIl8z7qgcjvnVezDuXA  
[gsheets] worksheets: [‘TEST1’]  
[gsheets] fetching host rows  
[gsheets] worksheet opened: TEST1  
[gsheets] total rows: 6  
[gsheets] total matched hosts: 5  
[gsheets] fetching groups  
[gsheets] total groups: 7  
[gsheets] start adding hosts  
[gsheets] adding host: (name=‘FGT60ETK19099QQQ’, address=‘172.29.252.1’, groups=[‘AUS’, ‘RB1’], description=‘AUS\_TEST1’)  
[gsheets] adding host: (name=‘FGT60ETK19099ZZZ’, address=‘172.29.252.8’, groups=[‘UK’, ‘andy’], description=‘UK\_TEST\_UK06’)  
[gsheets] adding host: (name=‘FGT60ETK19099YYY’, address=‘172.29.252.17’, groups=[‘GERMANY’, ‘RB2’], description=‘GERMANY\_TEST\_02’)  
[gsheets] adding host: (name=‘FGTTESTABC123’, address=‘172.29.255.250’, groups=[‘LAB’], description=‘branch2’)  
[gsheets] adding host: (name=‘FGTTESTABC456’, address=‘172.29.255.251’, groups=[‘LAB’, ‘andy’], description=‘branch3’)  
[gsheets] finished adding hosts  
{  
“AUS”: {  
“hosts”: [  
“FGT60ETK19099QQQ”  
]  
},  
“GERMANY”: {  
“hosts”: [  
“FGT60ETK19099YYY”  
]  
},  
“LAB”: {  
“hosts”: [  
“FGTTESTABC123”,  
“FGTTESTABC456”  
]  
},  
“RB1”: {  
“hosts”: [  
“FGT60ETK19099QQQ”  
]  
},  
“RB2”: {  
“hosts”: [  
“FGT60ETK19099YYY”  
]  
},  
“UK”: {  
“hosts”: [  
“FGT60ETK19099ZZZ”  
]  
},  
“\_meta”: {  
“hostvars”: {  
“FGT60ETK19099ZZZ”: {  
“\_awx\_description”: “UK\_TEST\_UK06”,  
“ansible\_host”: “172.29.252.8”,  
“appliance\_name”: “UK\_TEST\_UK06”,  
“gsheets\_credentials\_filepath”: “private/credentials.json”,  
“gsheets\_sheet\_id”: “1GacYZXvmEyGARBAGEB\_H5uVGIl8z7qgcjvnVezDuXA”,  
“gsheets\_worksheet\_name”: “TEST1”,  
“ipsec\_endpoint”: “18.39.191.70”,  
“is\_automated”: “YES”,  
“is\_onboarded”: “YES”,  
“management\_ip”: “172.29.252.8”,  
“model”: “FG-60E”,  
“rulebase”: “andy”,  
“serial”: “FGT60ETK19099ZZZ”,  
“wan1\_mode”: “FOOBARZ”  
},  
“FGT60ETK19099YYY”: {  
“\_awx\_description”: “GERMANY\_TEST\_02”,  
“ansible\_host”: “172.29.252.17”,  
“appliance\_name”: “GERMANY\_TEST\_02”,  
“gsheets\_credentials\_filepath”: “private/credentials.json”,  
“gsheets\_sheet\_id”: “1GacYZXvmEyGARBAGEB\_H5uVGIl8z7qgcjvnVezDuXA”,  
“gsheets\_worksheet\_name”: “TEST1”,  
“ipsec\_endpoint”: “18.39.191.70”,  
“is\_automated”: “YES”,  
“is\_onboarded”: “YES”,  
“management\_ip”: “172.29.252.17”,  
“model”: “FG-60E”,  
“rulebase”: “RB2”,  
“serial”: “FGT60ETK19099YYY”,  
“wan1\_mode”: “TEST2”  
},  
“FGT60ETK19099QQQ”: {  
“\_awx\_description”: “AUS\_TEST1”,  
“ansible\_host”: “172.29.252.1”,  
“appliance\_name”: “AUS\_TEST1”,  
“gsheets\_credentials\_filepath”: “private/credentials.json”,  
“gsheets\_sheet\_id”: “1GacYZXvmEyGARBAGEB\_H5uVGIl8z7qgcjvnVezDuXA”,  
“gsheets\_worksheet\_name”: “TEST1”,  
“ipsec\_endpoint”: “18.39.191.70”,  
“is\_automated”: “NO”,  
“is\_onboarded”: “YES”,  
“management\_ip”: “172.29.252.1”,  
“model”: “FG-60E”,  
“rulebase”: “RB1”,  
“serial”: “FGT60ETK19099QQQ”,  
“wan1\_mode”: “dhcp”  
},  
“FGTTESTABC123”: {  
“\_awx\_description”: “branch2”,  
“ansible\_host”: “172.29.255.250”,  
“appliance\_name”: “branch2”,  
“gsheets\_credentials\_filepath”: “private/credentials.json”,  
“gsheets\_sheet\_id”: “1GacYZXvmEyGARBAGEB\_H5uVGIl8z7qgcjvnVezDuXA”,  
“gsheets\_worksheet\_name”: “TEST1”,  
“ipsec\_endpoint”: “10.210.195.1”,  
“is\_automated”: “YES”,  
“is\_onboarded”: “YES”,  
“management\_ip”: “172.29.255.250”,  
“model”: “VM”,  
“serial”: “FGTTESTABC123”,  
“wan1\_mode”: “TEST123”  
},  
“FGTTESTABC456”: {  
“\_awx\_description”: “branch3”,  
“ansible\_host”: “172.29.255.251”,  
“appliance\_name”: “branch3”,  
“gsheets\_credentials\_filepath”: “private/credentials.json”,  
“gsheets\_sheet\_id”: “1GacYZXvmEyGARBAGEB\_H5uVGIl8z7qgcjvnVezDuXA”,  
“gsheets\_worksheet\_name”: “TEST1”,  
“ipsec\_endpoint”: “10.210.195.1”,  
“is\_automated”: “YES”,  
“is\_onboarded”: “YES”,  
“management\_ip”: “172.29.255.251”,  
“model”: “VM”,  
“rulebase”: “andy”,  
“serial”: “FGTTESTABC456”,  
“wan1\_mode”: “TEST456”  
}  
}  
},  
“all”: {  
“children”: [  
“AUS”,  
“GERMANY”,  
“LAB”,  
“RB1”,  
“RB2”,  
“UK”,  
“andy”,  
“ungrouped”  
]  
},  
“andy”: {  
“hosts”: [  
“FGT60ETK19099ZZZ”,  
“FGTTESTABC456”  
]  
}  
}

---

<div class="post-metadata">

**Author:** ![Andrew\_Mulheirn](https://avatars.discourse-cdn.com/v4/letter/a/7993a0/32.png) [@Andrew\_Mulheirn](https://forum.ansible.com/u/Andrew_Mulheirn)\
**Post date:** [July 21, 2022, 1:17pm UTC](https://forum.ansible.com/t/how-to-set-the-description-for-hosts-in-a-dynamic-inventory/36801/6 "2022-07-21T13:17:26Z")

</div>

Apologies - I didn’t answer your first question. This was using operator 0.23.0. I’m now using operator 0.25.0. (AWX 21.3.0)

---

<div class="post-metadata">

**Author:** ![Andrew\_Mulheirn](https://avatars.discourse-cdn.com/v4/letter/a/7993a0/32.png) [@Andrew\_Mulheirn](https://forum.ansible.com/u/Andrew_Mulheirn)\
**Post date:** [July 21, 2022, 2:57pm UTC](https://forum.ansible.com/t/how-to-set-the-description-for-hosts-in-a-dynamic-inventory/36801/7 "2022-07-21T14:57:37Z")

</div>

Hi there,

An update for you - it works!

I had set the inventory source to overwrite every time, but maybe it wasn’t doing that. Deleting the inventory hosts, and re-syncing the inventory now populates the description column as expected!

Really happy about that.

Thanks to the team who are answering questions on this - I really appreciate you taking the time.

Regards,  
Andrew

---

<div class="post-metadata">

**Author:** ![AWX\_Project](https://avatars.discourse-cdn.com/v4/letter/a/eada6e/32.png) [@AWX\_Project](https://forum.ansible.com/u/AWX_Project)\
**Post date:** [July 21, 2022, 5:51pm UTC](https://forum.ansible.com/t/how-to-set-the-description-for-hosts-in-a-dynamic-inventory/36801/8 "2022-07-21T17:51:48Z")

</div>

Awesome, glad you got this working! thanks for the update
