How to combine a dict list and an items list and read the item.key from the dict list

44 views
Skip to first unread message

Esteban Freire

unread,
Jun 8, 2015, 11:07:32 AM6/8/15
to ansible...@googlegroups.com
Hello all,

I have the following file in vars:

groups_account:
  project-institute:
    status: create
    create_group_admin: create
    group_admin_user: test3
    group_admin_Name: "Pepito"
    group_admin_fullName: 'GROUP_ADMIN_USER="Pepito de los palotes"'
    group_admin_type_authentication: core
    group_admin_default_view: 'DEFAULT_VIEW="cloud"'
    group_admin_mail: 'Email="algo@algo"'
    group_admin_telf: 'Telf="6123456789"'
    group_admin_role: 'role="admin"'
    group_admin_user_info: 'user_info="researcher"'
    group_admin_start_date: 'start_date="2015/12/13"'
    group_admin_end_date: 'end_date="2016/12/13"'
    group_admins_list: []
    start_date_project: 'start_date_project="2015/12/13"'
    end_date_project: 'end_date_project="2016/12/13"'
    group_admins_project: 'GroupAdmins_for_this_project="esteban, jose, pepe, ramon"'
    GROUP_CPU_QUOTA: 5000
    GROUP_IMAGES_SIZE_QUOTA: 50000
    GROUP_DB_SIZE_QUOTA: 100000
    network:
  project-institute2:
    status: create
    create_group_admin: nocreate
    group_admin_user:
    group_admin_Name: "PepitoIII"
    group_admin_fullName: 'GROUP_ADMIN_USER="Pepito de los palotes"'
    group_admin_type_authentication: core
    group_admin_default_view: 'DEFAULT_VIEW="cloud"'
    group_admin_mail: 'Email="algo2@algo"'
    group_admin_telf: 'Telf="6123456789"'
    group_admin_role: 'role="admin"'
    group_admin_user_info: 'user_info="researcher"'
    group_admin_start_date: 'start_date="2015/12/13"'
    group_admin_end_date: 'end_date="2016/12/13"'
    group_admins_list:
      - test1
    start_date_project: 'start_date_project="2015/12/13"'
    end_date_project: 'end_date_project="2016/12/13"'
    group_admins_project: 'GroupAdmins_for_this_project="esteban, jose, pepe, ramon"'
    GROUP_CPU_QUOTA: 5000
    GROUP_IMAGES_SIZE_QUOTA: 50000
    GROUP_DB_SIZE_QUOTA: 100000
    network:

Ant the following task:

- name: Adding the group as secondary group to the groupadmins list
  sudo: True
  sudo_user: oneadmin
  shell: check_if_user_exist=`oneuser show {{ item.1 }} > /dev/null 2>&1`;if [ $? == 0 ];then oneuser addgroup {{ item.1 }} {{ item.key }};fi
  with_subelements:
    - groups_account
    - group_admins_list
  when: (item.0.status == "create" and item.1 != "")
  tags:
    - create_group

But I get the following issue:

TASK: [testing | Adding the group as secondary group to the groupadmins list ] ***
<m-opennebula4> ESTABLISH CONNECTION FOR USER: root
fatal: [m-opennebula4] => One or more undefined variables: 'list object' has no attribute 'key'

It seems that the key (in this case project-institute*) is missing in this case and I don't know how to read it :/ .. Does anyone know how could I read this value combining both lists?

Thanks in advance,
Esteban

PS: .. Sorry for the bad explanation, I am really tired right now :/
Reply all
Reply to author
Forward
0 new messages