Skip to content

Commit 27a0cc9

Browse files
Merge pull request #776 from rk-it-at/feature_ansible_host_for_inventory
Feature ansible host for inventory
2 parents d4a8391 + ad98067 commit 27a0cc9

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
3+
minor_changes:
4+
- Dynamic Inventory Source - Add possibility to update ansible_host with ip address from Checkmk

plugins/inventory/checkmk.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@
2929
type: list
3030
elements: str
3131
required: false
32+
want_ipv4:
33+
description: Update ansible_host variable with ip address from Checkmk
34+
type: boolean
35+
required: false
3236
"""
3337

3438
EXAMPLES = """
@@ -44,6 +48,7 @@
4448
automation_secret: "******"
4549
validate_certs: false
4650
groupsources: ["hosttags", "sites"]
51+
want_ipv4: False
4752
"""
4853

4954
import json
@@ -73,6 +78,7 @@ def __init__(self):
7378
self.user = None
7479
self.secret = None
7580
self.validate_certs = None
81+
self.want_ipv4 = None
7682
self.groupsources = []
7783
self.hosttaggroups = []
7884
self.tags = []
@@ -141,6 +147,7 @@ def parse(self, inventory, loader, path, cache=False):
141147
self.user = self.get_option("automation_user")
142148
self.secret = self.get_option("automation_secret")
143149
self.validate_certs = self.get_option("validate_certs")
150+
self.want_ipv4 = self.get_option("want_ipv4")
144151
self.groupsources = self.get_option("groupsources")
145152
except Exception as e:
146153
raise AnsibleParserError("All correct options required: {}".format(e))
@@ -172,6 +179,10 @@ def _populate(self):
172179
self.inventory.add_host(host["id"])
173180
self.inventory.set_variable(host["id"], "ipaddress", host["ipaddress"])
174181
self.inventory.set_variable(host["id"], "folder", host["folder"])
182+
if self.want_ipv4:
183+
self.inventory.set_variable(
184+
host["id"], "ansible_host", host["ipaddress"]
185+
)
175186

176187
if self.groupsources:
177188
if "hosttags" in self.groupsources:

0 commit comments

Comments
 (0)