From fbc4797f753387fed0346c4ac05ec9a858911b9c Mon Sep 17 00:00:00 2001 From: Chris Meyers Date: Wed, 22 Feb 2017 10:44:50 -0500 Subject: [PATCH] Revert "Improve retrieving ip of container" --- files/docker_inspect.sh | 2 ++ tasks/inc_cloud_iface.yml | 13 +++++++++++-- tasks/inc_inventory_iface.yml | 6 ++++-- 3 files changed, 17 insertions(+), 4 deletions(-) create mode 100755 files/docker_inspect.sh diff --git a/files/docker_inspect.sh b/files/docker_inspect.sh new file mode 100755 index 0000000..085bcd7 --- /dev/null +++ b/files/docker_inspect.sh @@ -0,0 +1,2 @@ +#!/bin/bash +docker inspect --format='{{.NetworkSettings.IPAddress}}' $1 diff --git a/tasks/inc_cloud_iface.yml b/tasks/inc_cloud_iface.yml index 07817c6..5887075 100644 --- a/tasks/inc_cloud_iface.yml +++ b/tasks/inc_cloud_iface.yml @@ -17,13 +17,22 @@ - name: Get IP of container local_action: - module: "command" - args: "docker inspect --format '{{ '{{' }} .NetworkSettings.IPAddress {{ '}}' }}' {{ item.name }}" + module: "shell" + args: "{{ role_path }}/files/docker_inspect.sh {{ item.name }}" register: provision_docker_ip with_items: "{{ provision_docker_inventory }}" changed_when: false - block: + # Note: We had to move the invocation of the docker inspect command into a bash + # script because it involces a command line parameter with {{ }}. Registering + # the results puts the command line params into invocation. Referencing the + # results variable fails because Ansible runs the invocation through jinja2 + # template engine and the {{.NetworkSettings.IPAddress}} variable does not + # exist + # TODO: Check if no results (i.e. results.stdout_lines length) returned from + # docker_inspect.sh + # TODO: copy ALL host vars in the inventory - name: "Associate ip address with hosts" local_action: diff --git a/tasks/inc_inventory_iface.yml b/tasks/inc_inventory_iface.yml index f8cb395..07e9e2e 100644 --- a/tasks/inc_inventory_iface.yml +++ b/tasks/inc_inventory_iface.yml @@ -18,12 +18,14 @@ - name: Get IP of container local_action: - module: "command" - args: "docker inspect --format '{{ '{{' }} .NetworkSettings.IPAddress {{ '}}' }}' {{ item }}" + module: "shell" + args: "{{ role_path }}/files/docker_inspect.sh {{ item }}" register: provision_docker_ip with_items: "{{ provision_docker_inventory_group }}" changed_when: false +- debug: msg="{{provision_docker_ip}}" + - block: - name: "Associate ip address with hosts" set_fact: