Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Task skipping "Conditional result was False"

Tags:

ansible

I`m setting new ansible role to create new IPA users and groups. User creation works fine, but Im struggling with groups.

This is snippet from my vars and playbook. Ansible version is 2.4.2.0

vars:

ipagroups:
  ansible_group_test1:
    group: ansible_group_test1
    users:
    - ansible_test1
    - ansible_test2
  ansible_group_test2:
    group: ansible_group_test2
    users:
    - ansible_test1
    - ansible_test2
  ansible_group_test3:
    group: ansible_group_test3
    users:
    - ansible_test1
    - ansible_test2

task:

- name: adding ipa groups and  users
  ipa_group:
    name: "{{item.value.group}}"
    state: present
    user: "{{item.value.users}}"
    ipa_host: ipa.example.com
    ipa_user: admin
    ipa_pass: xxx
  with_dict: "{{ ipagroups }}"
  when: item.key == "ipagroups.keys()"

I expected the groups to be created, but I get: "skip_reason": "Conditional result was False"

Note: If I try it with e.g. when: item.key == 'ansible_group_test1' it works correctly

like image 946
Lubo Avatar asked Jul 20 '26 04:07

Lubo


1 Answers

I think you need when: item.key in ipagroups.keys()

I put your vars, verbatim, in group_vars/all, and have an empty inventory file. This playbook:


- hosts: localhost
  connection: local

  tasks:
  - name: Show vars
    debug:
      var: item.value.group
    when: item.key in ipagroups.keys()
    with_dict: "{{ ipagroups }}"

Gives me:

TASK [Show vars] ***************************************
ok: [localhost] => (item=None) => {
    "item.value.group": "ansible_group_test2"
}
ok: [localhost] => (item=None) => {
    "item.value.group": "ansible_group_test3"
}
ok: [localhost] => (item=None) => {
    "item.value.group": "ansible_group_test1"
}
like image 177
Jack Avatar answered Jul 22 '26 23:07

Jack