From 3f4bb511ca88fc501d9b4c149879fc382e708327 Mon Sep 17 00:00:00 2001 From: Alan Rominger Date: Mon, 28 Feb 2022 16:56:21 -0500 Subject: [PATCH 1/2] Add an inventory with changing vars for 100 hosts --- inventories/changes_100_hosts.py | 58 ++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100755 inventories/changes_100_hosts.py diff --git a/inventories/changes_100_hosts.py b/inventories/changes_100_hosts.py new file mode 100755 index 0000000000..500fdda2ea --- /dev/null +++ b/inventories/changes_100_hosts.py @@ -0,0 +1,58 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +import json + +from datetime import datetime + +# This is a useful script to determine what happens on an inventory import +# when the contents change. By using a timestamp, we should force the values +# herein to change every time the sync is done. +# +# There are 2 examples +# - demonstrate new / old hosts by changing the hostname returned each time +# which is relevant to `overwrite` +# - demonstrate `overwrite_vars` by including 2 sub-examples +# - variable changes its name on every import +# - variable changes its value on every import + + +def time_val(): + return datetime.utcnow().strftime('%Y_%m_%d_%H_%M_%S.%f') + + +host_names = [f'change_of_vars_{i}' for i in range(100)] + +hostvars = {} +for host in host_names: + hostvars[host] = { + "static_key": "host_dynamic_{}".format(time_val()), + "dynamic_{}".format(time_val()): "host_static_value" + } + + +print(json.dumps({ + "_meta": { + "hostvars": hostvars + }, + "all": { + "vars": { + "static_inventory_key": "inventory_dynamic_{}".format(time_val()), + "dynamic_{}".format(time_val()): "inventory_static_value" + } + }, + "group_with_moover": { + "hosts": host_names + }, + "group_with_vars": { + "hosts": host_names, + "vars": { + "static_group_key": "group_dynamic_{}".format(time_val()), + "dynamic_group_{}".format(time_val()): "group_static_value" + } + }, + "ungrouped": { + "hosts": [ + "change_of_vars" + ] + } +})) From de8789b9e1677b186ddf881026f226633d77aecf Mon Sep 17 00:00:00 2001 From: Alan Rominger Date: Mon, 28 Feb 2022 20:06:57 -0500 Subject: [PATCH 2/2] Larger array of inventory files --- inventories/changes_10000_hosts.py | 29 ++++++++++++++++++++++++++++ inventories/changes_1000_hosts.py | 29 ++++++++++++++++++++++++++++ inventories/changes_100_hosts.py | 31 +----------------------------- 3 files changed, 59 insertions(+), 30 deletions(-) create mode 100755 inventories/changes_10000_hosts.py create mode 100755 inventories/changes_1000_hosts.py diff --git a/inventories/changes_10000_hosts.py b/inventories/changes_10000_hosts.py new file mode 100755 index 0000000000..4e2f7553db --- /dev/null +++ b/inventories/changes_10000_hosts.py @@ -0,0 +1,29 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +import json + +from datetime import datetime + + +def time_val(): + return datetime.utcnow().strftime('%Y_%m_%d_%H_%M_%S.%f') + + +host_names = [f'change_of_vars_{i}' for i in range(10000)] + +hostvars = {} +for host in host_names: + hostvars[host] = { + "static_key": "host_dynamic_{}".format(time_val()), + "dynamic_{}".format(time_val()): "host_static_value" + } + + +print(json.dumps({ + "_meta": { + "hostvars": hostvars + }, + "ungrouped": { + "hosts": host_names + } +})) diff --git a/inventories/changes_1000_hosts.py b/inventories/changes_1000_hosts.py new file mode 100755 index 0000000000..558a5c1d94 --- /dev/null +++ b/inventories/changes_1000_hosts.py @@ -0,0 +1,29 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +import json + +from datetime import datetime + + +def time_val(): + return datetime.utcnow().strftime('%Y_%m_%d_%H_%M_%S.%f') + + +host_names = [f'change_of_vars_{i}' for i in range(1000)] + +hostvars = {} +for host in host_names: + hostvars[host] = { + "static_key": "host_dynamic_{}".format(time_val()), + "dynamic_{}".format(time_val()): "host_static_value" + } + + +print(json.dumps({ + "_meta": { + "hostvars": hostvars + }, + "ungrouped": { + "hosts": host_names + } +})) diff --git a/inventories/changes_100_hosts.py b/inventories/changes_100_hosts.py index 500fdda2ea..62d093fd9a 100755 --- a/inventories/changes_100_hosts.py +++ b/inventories/changes_100_hosts.py @@ -4,17 +4,6 @@ from datetime import datetime -# This is a useful script to determine what happens on an inventory import -# when the contents change. By using a timestamp, we should force the values -# herein to change every time the sync is done. -# -# There are 2 examples -# - demonstrate new / old hosts by changing the hostname returned each time -# which is relevant to `overwrite` -# - demonstrate `overwrite_vars` by including 2 sub-examples -# - variable changes its name on every import -# - variable changes its value on every import - def time_val(): return datetime.utcnow().strftime('%Y_%m_%d_%H_%M_%S.%f') @@ -34,25 +23,7 @@ def time_val(): "_meta": { "hostvars": hostvars }, - "all": { - "vars": { - "static_inventory_key": "inventory_dynamic_{}".format(time_val()), - "dynamic_{}".format(time_val()): "inventory_static_value" - } - }, - "group_with_moover": { - "hosts": host_names - }, - "group_with_vars": { - "hosts": host_names, - "vars": { - "static_group_key": "group_dynamic_{}".format(time_val()), - "dynamic_group_{}".format(time_val()): "group_static_value" - } - }, "ungrouped": { - "hosts": [ - "change_of_vars" - ] + "hosts": host_names } }))