Unsure how to merge this dict/list into a single dict/list

26 views
Skip to first unread message

ppo...@greenlancer.com

unread,
Jun 20, 2016, 4:14:22 PM6/20/16
to Ansible Project
- name: Jinja Example Playbook
  hosts
: localhost
  connection
: local
  vars_files
:
   
- test-role/defaults/container.yml
   
- test-role/defaults/container_env.yml
  vars
:
    combined_containers
: "{{ (containers + container_env) | unique}}"
 
  tasks
:
   
- name: Container file
      debug
:
        msg
: "{{containers}}"
   
- name: Container env file
      debug
:
        msg
: "{{container_env}}"
   
- name: Combined
      debug
:
        msg
: "{{combined_containers}}"
   
- debug:
        msg
: "{{item.name}} - {{item.version}} - {{item.env}}"
      with_items
:        
         
- "{{combined_containers}}"

---
container_env
:
 
- name: httpd
    env
: Phil
 
- name: httpd
    env
: Phil

---
containers:
  - name: httpd
    version: 2.4
  - name: httpd
    env: Phil

PLAY [Jinja Example Playbook] **************************************************
 
TASK
[setup] *******************************************************************
ok
: [localhost]
 
TASK
[Container file] **********************************************************
ok
: [localhost] => {
   
"msg": [
       
{
           
"name": "httpd",
           
"version": 2.4
       
},
       
{
           
"env": "Phil",
           
"name": "httpd"
       
}
   
]
}
 
TASK
[Container env file] ******************************************************
ok
: [localhost] => {
   
"msg": [
       
{
           
"env": "Phil",
           
"name": "httpd"
       
},
       
{
           
"env": "Phil",
           
"name": "httpd"
       
}
   
]
}
 
TASK
[Combined] ****************************************************************
ok
: [localhost] => {
   
"msg": [
       
{
           
"name": "httpd",
           
"version": 2.4
       
},
       
{
           
"env": "Phil",
           
"name": "httpd"
       
}
   
]
}
 
TASK
[debug] *******************************************************************
fatal
: [localhost]: FAILED! => {"failed": true, "msg": "'dict object' has no attribute 'env'"}  



I am expecting to receive a combined list like this. What can I do to accomplish that?
 
  "msg": [
       
{
           
"name": "httpd",
           
"version": 2.4,
           
"env": "Phil"
       
}    
   
]



The information contained in this transmission (including any attachments) is confidential and may be privileged. It is intended only for the use of the individual or entity named above. If you are not the intended recipient, dissemination, distribution, or copy of this communication is strictly prohibited. If you have received this communication in error, please erase all copies of this message and its attachments and notify me immediately.

Mike Biancaniello

unread,
Jun 21, 2016, 11:21:36 AM6/21/16
to Ansible Project
Reply all
Reply to author
Forward
0 new messages