{"id":7833,"date":"2025-11-07T08:02:59","date_gmt":"2025-11-07T14:02:59","guid":{"rendered":"https:\/\/gregsowell.com\/?p=7833"},"modified":"2025-11-07T08:03:12","modified_gmt":"2025-11-07T14:03:12","slug":"satellite-custom-host-variables-into-ansible-automation-platform","status":"publish","type":"post","link":"https:\/\/gregsowell.com\/?p=7833","title":{"rendered":"Satellite Custom Host Variables Into Ansible Automation Platform"},"content":{"rendered":"<p><a href=\"https:\/\/gregsowell.com\/wp-content\/uploads\/2025\/11\/thumbnail.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/gregsowell.com\/wp-content\/uploads\/2025\/11\/thumbnail-300x169.jpg\" alt=\"\" width=\"300\" height=\"169\" class=\"aligncenter size-medium wp-image-7848\" srcset=\"https:\/\/gregsowell.com\/wp-content\/uploads\/2025\/11\/thumbnail-300x169.jpg 300w, https:\/\/gregsowell.com\/wp-content\/uploads\/2025\/11\/thumbnail-768x432.jpg 768w, https:\/\/gregsowell.com\/wp-content\/uploads\/2025\/11\/thumbnail-1024x576.jpg 1024w, https:\/\/gregsowell.com\/wp-content\/uploads\/2025\/11\/thumbnail.jpg 1280w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a>This one is MUCH more niche than my typical blog posts, but a customer asked, so here I am.<\/p>\n<p>A customer has all of their hosts i Red Hat&#8217;s Satellite product, so this will be their source of truth(the place that holds a list of all hosts).<br \/>\nThey are using Satellite as a dynamic inventory source(filling out an AAP inventory automatically).<br \/>\nThey want some kind of defining information in the form of variables to automatically come from Satellite that they can use in their automations to do specific configuration on their hosts.<\/p>\n<p>TLDR; get custom variables from Satellite that is available to playbooks in AAP.<br \/>\nI use parameters inside of Satellite host groups.<\/p>\n<h2>Video Overview<\/h2>\n<p><iframe loading=\"lazy\" width=\"560\" height=\"315\" src=\"https:\/\/www.youtube.com\/embed\/JyFRoCRb7KI?si=AfcH1EJT4CF84sUj\" title=\"YouTube video player\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe><\/p>\n<h2>Configure Satellite<\/h2>\n<p>I&#8217;m using host groups here to maintain custom parameters.  I&#8217;m guessing this can be done in other ways, but this was the one that seemed to fit my use case the best.<\/p>\n<p>Go to configure, then Host Groups, and last click Create Host Group(unless you are already utilizing HGs, then just skip to the next step):<br \/>\n<a href=\"https:\/\/gregsowell.com\/wp-content\/uploads\/2025\/11\/Screenshot_1.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/gregsowell.com\/wp-content\/uploads\/2025\/11\/Screenshot_1-300x100.png\" alt=\"\" width=\"300\" height=\"100\" class=\"aligncenter size-medium wp-image-7834\" srcset=\"https:\/\/gregsowell.com\/wp-content\/uploads\/2025\/11\/Screenshot_1-300x100.png 300w, https:\/\/gregsowell.com\/wp-content\/uploads\/2025\/11\/Screenshot_1-768x255.png 768w, https:\/\/gregsowell.com\/wp-content\/uploads\/2025\/11\/Screenshot_1-1024x340.png 1024w, https:\/\/gregsowell.com\/wp-content\/uploads\/2025\/11\/Screenshot_1.png 1133w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>Next name the host group and then click the Parameters tab:<br \/>\n<a href=\"https:\/\/gregsowell.com\/wp-content\/uploads\/2025\/11\/Screenshot_2.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/gregsowell.com\/wp-content\/uploads\/2025\/11\/Screenshot_2-300x120.png\" alt=\"\" width=\"300\" height=\"120\" class=\"aligncenter size-medium wp-image-7835\" srcset=\"https:\/\/gregsowell.com\/wp-content\/uploads\/2025\/11\/Screenshot_2-300x120.png 300w, https:\/\/gregsowell.com\/wp-content\/uploads\/2025\/11\/Screenshot_2.png 594w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>Click +Add Parameter, then give they key for your variable, and give it a value.  With my customer in question it would be a list of packages to add to a host, but really any information can be stored.  Keep in mind you can add multiple key\/value pairs here to suit your needs:<br \/>\n<a href=\"https:\/\/gregsowell.com\/wp-content\/uploads\/2025\/11\/Screenshot_3.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/gregsowell.com\/wp-content\/uploads\/2025\/11\/Screenshot_3-300x142.png\" alt=\"\" width=\"300\" height=\"142\" class=\"aligncenter size-medium wp-image-7836\" srcset=\"https:\/\/gregsowell.com\/wp-content\/uploads\/2025\/11\/Screenshot_3-300x142.png 300w, https:\/\/gregsowell.com\/wp-content\/uploads\/2025\/11\/Screenshot_3.png 582w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>You now need to add hosts to your host group.  There are a few different ways to accomplish this:<br \/>\n&#8211; When adding a new host, just select the host group there<br \/>\n&#8211; Specify it in the activation key you utilize<br \/>\n&#8211; Put it in the provisioning template you use to create a host with<br \/>\n&#8211; Create a discovery rule(this will also grab existing hosts and properly add them to the group)<\/p>\n<p>In this example I&#8217;m just going to manually edit one of the hosts and set the host group; this is the quickest way to do a quick demo:<br \/>\n<a href=\"https:\/\/gregsowell.com\/wp-content\/uploads\/2025\/11\/Screenshot_4.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/gregsowell.com\/wp-content\/uploads\/2025\/11\/Screenshot_4-300x44.png\" alt=\"\" width=\"300\" height=\"44\" class=\"aligncenter size-medium wp-image-7838\" srcset=\"https:\/\/gregsowell.com\/wp-content\/uploads\/2025\/11\/Screenshot_4-300x44.png 300w, https:\/\/gregsowell.com\/wp-content\/uploads\/2025\/11\/Screenshot_4-768x113.png 768w, https:\/\/gregsowell.com\/wp-content\/uploads\/2025\/11\/Screenshot_4-1024x151.png 1024w, https:\/\/gregsowell.com\/wp-content\/uploads\/2025\/11\/Screenshot_4.png 1168w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><br \/>\n<a href=\"https:\/\/gregsowell.com\/wp-content\/uploads\/2025\/11\/Screenshot_5.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/gregsowell.com\/wp-content\/uploads\/2025\/11\/Screenshot_5-300x178.png\" alt=\"\" width=\"300\" height=\"178\" class=\"aligncenter size-medium wp-image-7839\" srcset=\"https:\/\/gregsowell.com\/wp-content\/uploads\/2025\/11\/Screenshot_5-300x178.png 300w, https:\/\/gregsowell.com\/wp-content\/uploads\/2025\/11\/Screenshot_5.png 498w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><br \/>\n<a href=\"https:\/\/gregsowell.com\/wp-content\/uploads\/2025\/11\/Screenshot_6.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/gregsowell.com\/wp-content\/uploads\/2025\/11\/Screenshot_6-300x86.png\" alt=\"\" width=\"300\" height=\"86\" class=\"aligncenter size-medium wp-image-7840\" srcset=\"https:\/\/gregsowell.com\/wp-content\/uploads\/2025\/11\/Screenshot_6-300x86.png 300w, https:\/\/gregsowell.com\/wp-content\/uploads\/2025\/11\/Screenshot_6-768x219.png 768w, https:\/\/gregsowell.com\/wp-content\/uploads\/2025\/11\/Screenshot_6.png 915w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<h2>AAP Configuration<\/h2>\n<p>I&#8217;m not going to cover configuring the dynamic inventory source as that&#8217;s actually a pretty simple process, rather I&#8217;m going to show how the variable is now pulled in from Satellite.<\/p>\n<p>In AAP, I go to Inventories and choose the correct inventory:<br \/>\n<a href=\"https:\/\/gregsowell.com\/wp-content\/uploads\/2025\/11\/Screenshot_7.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/gregsowell.com\/wp-content\/uploads\/2025\/11\/Screenshot_7-300x175.png\" alt=\"\" width=\"300\" height=\"175\" class=\"aligncenter size-medium wp-image-7841\" srcset=\"https:\/\/gregsowell.com\/wp-content\/uploads\/2025\/11\/Screenshot_7-300x175.png 300w, https:\/\/gregsowell.com\/wp-content\/uploads\/2025\/11\/Screenshot_7.png 682w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>I then click on the Sources tab(where dynamic inventory sources live) and tell the Satellite inventory source to resync:<br \/>\n<a href=\"https:\/\/gregsowell.com\/wp-content\/uploads\/2025\/11\/Screenshot_8.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/gregsowell.com\/wp-content\/uploads\/2025\/11\/Screenshot_8-300x155.png\" alt=\"\" width=\"300\" height=\"155\" class=\"aligncenter size-medium wp-image-7842\" srcset=\"https:\/\/gregsowell.com\/wp-content\/uploads\/2025\/11\/Screenshot_8-300x155.png 300w, https:\/\/gregsowell.com\/wp-content\/uploads\/2025\/11\/Screenshot_8-768x397.png 768w, https:\/\/gregsowell.com\/wp-content\/uploads\/2025\/11\/Screenshot_8.png 810w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>I&#8217;m then going to click on the Hosts tab and choose the host that was added to my Satellite host group:<br \/>\n<a href=\"https:\/\/gregsowell.com\/wp-content\/uploads\/2025\/11\/Screenshot_9.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/gregsowell.com\/wp-content\/uploads\/2025\/11\/Screenshot_9-300x137.png\" alt=\"\" width=\"300\" height=\"137\" class=\"aligncenter size-medium wp-image-7843\" srcset=\"https:\/\/gregsowell.com\/wp-content\/uploads\/2025\/11\/Screenshot_9-300x137.png 300w, https:\/\/gregsowell.com\/wp-content\/uploads\/2025\/11\/Screenshot_9.png 711w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>Taking a look at the variables for the host(these all came from Satellite), I can see the parameters I configured for the Satellite host group appended to the end:<br \/>\n<a href=\"https:\/\/gregsowell.com\/wp-content\/uploads\/2025\/11\/Screenshot_10.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/gregsowell.com\/wp-content\/uploads\/2025\/11\/Screenshot_10-300x235.png\" alt=\"\" width=\"300\" height=\"235\" class=\"aligncenter size-medium wp-image-7844\" srcset=\"https:\/\/gregsowell.com\/wp-content\/uploads\/2025\/11\/Screenshot_10-300x235.png 300w, https:\/\/gregsowell.com\/wp-content\/uploads\/2025\/11\/Screenshot_10.png 621w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>To utilize this variable in a playbook I can use the &#8220;hostvars&#8221; variable, which will give you access to any variables defined for the host.  I use an additional magic variable &#8220;inventory_hostname&#8221;, to specify in my tasks which host to grab the variables of; inventory_hostname is the name of the host currently being processed.<\/p>\n<pre class=\"gs-code\"><code class=\"language-plaintext\">hostvars[inventory_hostname].testparm1<\/code><\/pre>\n<p>I have a simple playbook that will display the contents of &#8220;testparm1&#8221; for all hosts that have it defined:<\/p>\n<pre class=\"gs-code\"><code class=\"language-plaintext\">---\r\n- name: Display the testparm1 variable for all hosts in a Satellite synced inventory\r\n  hosts: all\r\n  gather_facts: false\r\n  tasks:\r\n    - name: display testparm1 variable\r\n      when: hostvars[inventory_hostname].testparm1 is defined\r\n      ansible.builtin.debug:\r\n        var: hostvars[inventory_hostname].testparm1<\/code><\/pre>\n<p>The result of the playbook run:<br \/>\n<a href=\"https:\/\/gregsowell.com\/wp-content\/uploads\/2025\/11\/Screenshot_11.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/gregsowell.com\/wp-content\/uploads\/2025\/11\/Screenshot_11-300x205.png\" alt=\"\" width=\"300\" height=\"205\" class=\"aligncenter size-medium wp-image-7845\" srcset=\"https:\/\/gregsowell.com\/wp-content\/uploads\/2025\/11\/Screenshot_11-300x205.png 300w, https:\/\/gregsowell.com\/wp-content\/uploads\/2025\/11\/Screenshot_11.png 632w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><br \/>\nYou can see that for the only host added to my Satellite host group(node1), it correctly returned the value for testparm1!<\/p>\n<h2>Conclusion<\/h2>\n<p>This is not an Earth shattering development, but it can be exceptionally useful for configuring and maintaining hosts in your infrastructure.  If you have any questions or comments, please reach out; I love hearing from folks \ud83d\ude42  Good luck and happy automating!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This one is MUCH more niche than my typical blog posts, but a customer asked, so here I am. A customer has all of\u2026<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[49,13],"tags":[],"class_list":["post-7833","post","type-post","status-publish","format-standard","hentry","category-ansible","category-server"],"_links":{"self":[{"href":"https:\/\/gregsowell.com\/index.php?rest_route=\/wp\/v2\/posts\/7833","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gregsowell.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gregsowell.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gregsowell.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/gregsowell.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=7833"}],"version-history":[{"count":4,"href":"https:\/\/gregsowell.com\/index.php?rest_route=\/wp\/v2\/posts\/7833\/revisions"}],"predecessor-version":[{"id":7849,"href":"https:\/\/gregsowell.com\/index.php?rest_route=\/wp\/v2\/posts\/7833\/revisions\/7849"}],"wp:attachment":[{"href":"https:\/\/gregsowell.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7833"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gregsowell.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=7833"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gregsowell.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=7833"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}