-1

I'm trying to get an ip adress from an docker container w/ ansible-module docker_container_info. Following is my suspection how it would be get excluded from the result.

  - name: Get infos on container
    docker_container_info:
      name: nextcloud-db
    register: result_container
  - name: Dump grep matching interfaces from ansible_interfaces
    set_fact:
       interfaces_list: "{{ result_container | select('match', '^IPAddress') }}"
  - debug:
      var: result_container
  - debug:
      var: interfaces_list

while trying this i get this error

TASK [debug] ******************************************************************************************************************************************************************************************************
ok: [localhost] => {
    "interfaces_list": "<generator object select_or_reject at 0x7f2bb30d55a0>"
}

How do i extract the ip address from this result else? The goal is to create an variable that i can use later to dump an database and import it to another docker container.

TheRojam
  • 121
  • 6

1 Answers1

0

The below should works for me:

- hosts: localhost
  sudo: yes

  tasks: 
    - name: Get infos on container
      docker_container_info:
        name: <some_name>
      register: result
    
    - debug:
        var: result | json_query('container.NetworkSettings.[IPAddress]')

play output:

PLAY [localhost] ***********************************************************************************************************************************************************

TASK [Gathering Facts] *****************************************************************************************************************************************************
ok: [localhost]

TASK [Get infos on container] **********************************************************************************************************************************************
ok: [localhost]

TASK [debug] ***************************************************************************************************************************************************************
ok: [localhost] => {
    "result | json_query('container.NetworkSettings.[IPAddress]')": [
        "172.17.0.2"
    ]
}

PLAY RECAP *****************************************************************************************************************************************************************
localhost                  : ok=3    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0
error404
  • 2,684
  • 2
  • 13
  • 21