antonroman / dockemu-ansible

New implementation of Dockemu simulation framework based on Ansible
GNU General Public License v3.0
3 stars 2 forks source link

Use stdout_lines to access list of pid containers instead of stdout string #1

Open antonroman opened 5 years ago

antonroman commented 5 years ago

Currently we are using the commands below to get the list of PID from the containers:

- name: split stdout_lines into variable
   tags:
             - execute  
   set_fact: 
             blockdevices1: "{{list_of_containers.results|map(attribute='stdout')|list}}"

- name: split stdout_lines into variable
   tags:
           - execute
    set_fact:
           blockdevices2: "{{blockdevices1[0].split('\n')}}"      

 - name: get PID from containers
    tags:
             - prepare
             - execute
   shell:  "docker inspect --format '{''{ .State.Pid }''}' {{ item }}"
   register: list_pids
   with_items:
            - "{{ blockdevices2 }}"

We should be able to get it using the code below directly however it doesn't seem to be working properly directly in the docker command:

with_items:
             - "{{ list_of_containers.results|map(attribute='stdout_lines')|list }}"

Need to check why this is not working as expected

antonroman commented 5 years ago

Reference: https://carlosonunez.wordpress.com/2016/02/25/winning-at-ansible-how-to-manipulate-items-in-a-list/