aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuido Günther <agx@sigxcpu.org>2016-06-17 15:10:07 +0200
committerGuido Günther <agx@sigxcpu.org>2016-06-17 15:15:02 +0200
commit2edd1107a30b485514a9f8a9ad1d2b5871423e84 (patch)
treeff8716d60515d77ce1bba8434bfdc6a4add3e324
parent9c6c4efdab172c005958f08a30f91fadf8268f03 (diff)
Set host ip as fact when creating the host
-rw-r--r--README.md2
-rw-r--r--foremanhost.py7
2 files changed, 7 insertions, 2 deletions
diff --git a/README.md b/README.md
index 2ad5986..552e805 100644
--- a/README.md
+++ b/README.md
@@ -6,7 +6,7 @@ Usage:
ansible-playbook --module-path . -c local -i localhost, example.yml
-The file [example.yml][] has an example.
+The file [example.yml](./example.yml) has an example.
[the Foreman]: http://theforeman.org
[Ansible]: http://ansible.com
diff --git a/foremanhost.py b/foremanhost.py
index 3309ee6..5fa7199 100644
--- a/foremanhost.py
+++ b/foremanhost.py
@@ -361,6 +361,7 @@ def core(module):
image_id = None
subnet = None
changed = False
+ facts = {}
ret = {}
host_url = "%s/api/v2/hosts" % api_url
@@ -393,7 +394,9 @@ def core(module):
interfaces)
try:
ret = do_post(host_url, fulljson, headers)
- hid = json.loads(ret['text'])['id']
+ j = json.loads(ret['text'])
+ hid = j['id']
+ facts['foremanhost_ip'] = j['ip']
changed = True
except requests.exceptions.HTTPError as e:
if is_exists(e):
@@ -440,6 +443,8 @@ def core(module):
raise ValueError("Unknown state %s" % state)
ret['changed'] = changed
+ if facts:
+ ret['ansible_facts'] = facts
return FOREMAN_SUCCESS, ret