From 2edd1107a30b485514a9f8a9ad1d2b5871423e84 Mon Sep 17 00:00:00 2001 From: Guido Günther Date: Fri, 17 Jun 2016 15:10:07 +0200 Subject: Set host ip as fact when creating the host --- README.md | 2 +- foremanhost.py | 7 ++++++- 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 -- cgit v1.2.3