Skip to content
Nov 19 / Greg

Why Am I Larry Sowell

Hey everybody, I’m Greg Sowell and this is Why Am I, a podcast where I talk to interesting people and try to trace a path to where they find themselves today.  My guest this go around is Larry Sowell.  This is a special episode, and something I’d like to try more of, so let me know what you think.  Larry is my uncle who lives in one of the oldest towns in Texas named Nacogdoches.  One of his favorite past times is picking pecans in the various parks there, so we go for a walk and talk while we pick up some good’uns.  We go from talking about the various species of nuts there to him as a child, then over to children leaving the nest…it’s an all over the place conversation, which is just the way I like it.  I hope you enjoy this conversation with Larry. Help us grow by sharing with someone!
Youtube version here:

Please show them some love on their socials here: GASP…he doesn’t use socials LOLOL

If you want to support the podcast you can do so via https://www.patreon.com/whyamipod (this gives you access to bonus content including their Fantasy Restaurant!)

Nov 12 / Greg

Fantasy Restaurant Judd Fink

Welcome to the warmup exercise for the Why Am I podcast called “the Fantasy Restaurant.”  In here my guests get to pick their favorite: drink, appetizer, main, sides, and dessert…anything goes. This dude puts together a great meal…I mean he adds Italian garlic bread…have you ever had a bad time while eating garlic bread…I rest my case.  I hope you enjoy this meal with Judd. Help us grow by sharing with someone!
Youtube version here:
If you want to support the podcast you can do so via https://www.patreon.com/whyamipod (this gives you access to bonus content including their Fantasy Restaurant!)
Nov 5 / Greg

Why Am I Judd Fink

Hey everybody, I’m Greg Sowell and this is Why Am I, a podcast where I talk to interesting people and try to trace a path to where they find themselves today.  My guest this go around is Judd Fink.  As a child he could speak to spirits.  He let that side of him go as he grew, but has finally reconnected with that part of him in his life coaching. Judd’s coaching seems to surround positive thinking along with spirituality.  His mantra seems to be “It’s all learning”, so join us and learn a little more about how we are all energy.  I hope you enjoy this chat with Judd. Help us grow by sharing with someone!
Youtube version here:
If you want to support the podcast you can do so via https://www.patreon.com/whyamipod (this gives you access to bonus content including their Fantasy Restaurant!)
Oct 29 / Greg

Fantasy Restaurant Kayleigh Grant

Welcome to the warmup exercise for the Why Am I podcast called “the Fantasy Restaurant.” In here my guests get to pick their favorite: drink, appetizer, main, sides, and dessert…anything goes. This is another vegetarian meal, but it is packed with flavors and textures…I think maybe enough to satiate any palette. Word of warning, I was on the tail end of a bad cold, so there are some random pauses for me to cough, and I likely sound a little rough! I hope you enjoy this meal with Kayleigh.Help us grow by sharing with someone!

Youtube version here:
If you want to support the podcast you can do so via https://www.patreon.com/whyamipod (this gives you access to bonus content including their Fantasy Restaurant!)
Oct 23 / Greg

Ascender And AWX Custom Dynamic Inventory Scripts


When using inventories in Ascender and AWX it’s often advantageous to take advantage of dynamic inventories. This really just means a way to query a Configuration Management Database(CMDB) for a list of hosts and their variables. There are many ways baked into Ascender to do this with services like Amazon, Google, or VMWare, but what about when it’s a CMDB that’s not on that list; that’s where custom dynamic inventory scripts come in! They allow you to query any system or digest any file to build an inventory dynamically.

Video

Scripts

You can find my scripts here in my git repository.

First is my sample JSON data file[json-payload]:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
{
  "hosts": [
    {
      "id": 1,
      "hostname": "host1.example.com",
      "ip_address": "192.168.1.101",
      "status": "active",
      "os": "Linux",
      "owner": "Admin User"
    },
    {
      "id": 2,
      "hostname": "host2.example.com",
      "ip_address": "192.168.1.102",
      "status": "inactive",
      "os": "Windows",
      "owner": "User 1"
    },
    {
      "id": 3,
      "hostname": "host3.example.com",
      "ip_address": "192.168.1.103",
      "status": "active",
      "os": "Linux",
      "owner": "User 2"
    },
    {
      "id": 4,
      "hostname": "host4.example.com",
      "ip_address": "192.168.1.104",
      "status": "active",
      "os": "Windows",
      "owner": "User 3"
    },
    {
      "id": 5,
      "hostname": "host5.example.com",
      "ip_address": "192.168.1.105",
      "status": "inactive",
      "os": "Linux",
      "owner": "User 4"
    }
  ]
}

As you can see, this is a simple set of JSON data that could be returned via my CMDB. Remember, this can be live querying or consumed via file. This list is five different hosts with a mix of variables.

Now for the custom dynamic inventory script [custom_inventory.py].

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/env python
#test import script
import json
 
# Specify the path to the JSON payload file
json_payload_file = 'json-payload'
 
# Read the JSON payload from the file
with open(json_payload_file, 'r') as file:
    json_payload = file.read()
 
# Parse the JSON payload
inventory_data = json.loads(json_payload)
 
# Initialize inventory data structures
ansible_inventory = {
    '_meta': {
        'hostvars': {}
    },
    'all': {
        'hosts': [],
        'vars': {
            # You can define global variables here
        }
    }
}
 
# Initialize group dictionaries for each OS
os_groups = {}
 
# Process each host in the JSON payload
for host in inventory_data['hosts']:
    host_id = host['id']
    hostname = host['hostname']
    ip_address = host['ip_address']
    status = host['status']
    os = host['os']
    owner = host['owner']
 
    # Add the host to the 'all' group
    ansible_inventory['all']['hosts'].append(hostname)
 
    # Create host-specific variables
    host_vars = {
        'ansible_host': ip_address,
        'status': status,
        'os': os,
        'owner': owner
        # Add more variables as needed
    }
 
    # Add the host variables to the '_meta' dictionary
    ansible_inventory['_meta']['hostvars'][hostname] = host_vars
 
    # Add the host to the corresponding OS group
    if os not in os_groups:
        os_groups[os] = {
            'hosts': []
        }
    os_groups[os]['hosts'].append(hostname)
 
# Add the OS groups to the inventory
ansible_inventory.update(os_groups)
 
# Print the inventory in JSON format
print(json.dumps(ansible_inventory, indent=4))

Note: make sure to make the file executable before uploading to your git repository or you will kick a permissions error when running the script on Ascender.

The whole first half of the script is pretty standard across all scripts. It begins to vary when I setup the variable for dynamic group mapping

1
2
# Initialize group dictionaries for each OS
os_groups = {}

This isn’t a requirement, but is certainly a big value add. I’m going to be grouping the hosts based on OS type, so I create the os_groups variable to store that info.

1
2
3
4
5
6
7
8
9
10
11
# Process each host in the JSON payload
for host in inventory_data['hosts']:
    host_id = host['id']
    hostname = host['hostname']
    ip_address = host['ip_address']
    status = host['status']
    os = host['os']
    owner = host['owner']
 
    # Add the host to the 'all' group
    ansible_inventory['all']['hosts'].append(hostname)

This section processes the info from the JSON payload and maps it to some standard variables for later use. I last add each host to the “all” inventory group.

1
2
3
4
5
6
7
8
9
10
11
    # Create host-specific variables
    host_vars = {
        'ansible_host': ip_address,
        'status': status,
        'os': os,
        'owner': owner
        # Add more variables as needed
    }
 
    # Add the host variables to the '_meta' dictionary
    ansible_inventory['_meta']['hostvars'][hostname] = host_vars

Here I’m creating the host_vars section(all of the variables saved for each host in the inventory).

1
2
3
4
5
6
7
8
9
   # Add the host to the corresponding OS group
    if os not in os_groups:
        os_groups[os] = {
            'hosts': []
        }
    os_groups[os]['hosts'].append(hostname)
 
# Add the OS groups to the inventory
ansible_inventory.update(os_groups)

Last I’m creating the os groups and then adding each host to its corresponding group.

Ascender Configuration

The Ascender config is pretty straightforward. Start by adding a project in pointing to the script repository:

Now I attach the script to an inventory. I first either create or enter an inventory:

Once in the inventory I click the “Sources” tab and click “Add”:

From here, give the source a name, choose “Sourced from a Project” under Source, select out newly created project, and last choose the new inventory script:

Some notes in this section. At the bottom there are some checkbox options.
Overwrite will wipe everything(hosts, groups, variables) and replace it with what is returned from the script.
Overwrite variables will wipe all variables and replace them with script return data.
Update on launch will force this script to rerun each time the inventory is used(this is often a desired option).

To manually synchronize, simply click the “Sync” button.

To view status or debug what is happening or happened in your sync, click Last Job Status:

You can checkout the results of the sync by going to the host section in your inventory:

Conclusion

The dynamic inventory sources are a powerful way to extend the usefulness of Ascender. Dynamic is the name of the game, as it keeps your automations as flexible as possible.

If you have any questions or concerns, if there are any tweaks or tunes you’d make, please reach out, I’d love to hear from you.

Thanks and happy automating!

Oct 22 / Greg

Why Am I Kayleigh Grant

Hey everybody, I’m Greg Sowell and this is Why Am I, a podcast where I talk to interesting people and try to trace a path to where they find themselves today.  My guest this go around is Kayleigh Grant.  Most folks know her as the guide that boops sharks…as in she free dives with sharks of all kinds and physically interacts with these toddlers of the ocean.  No doubt it’s a unique experience, but more importantly, people need to expand their world.  If you can learn to love a shark, just imagine what that means for your fellow humans.  Word of warning, I was on the tail end of a bad cold, so there are some random pauses for me to cough, and I likely sound a little rough!  At any rate, I hope you enjoy this chat with Kayleigh. Help us grow by sharing with someone!
Youtube version here:
If you want to support the podcast you can do so via https://www.patreon.com/whyamipod (this gives you access to bonus content including their Fantasy Restaurant!)
Oct 8 / Greg

Why Am I Lauren Auer

Hey everybody, I’m Greg Sowell and this is Why Am I, a podcast where I talk to interesting people and try to trace a path to where they find themselves today. My guest this go around is Lauren Auer(hour). She’s a mom of two, military wife, and a trauma counselor. Her practical, scientific approach to her work is interesting in and of itself, but the fact that she takes what she learns and shares it via blogs and social media to a huge audience, is amazing. We need more people who care about others and have the capacity to help, to have their voices amplified. I hope you enjoy this conversation with Lauren. Help us grow by sharing with someone!
Youtube version here:
If you want to support the podcast you can do so via https://www.patreon.com/whyamipod (this gives you access to bonus content including their Fantasy Restaurant!)