# I got error 'dict object' has no attribute 'state' when use state in when

**URL:** <https://forum.ansible.com/t/i-got-error-dict-object-has-no-attribute-state-when-use-state-in-when/22556>\
**Category:** Ansible Project\
**Created:** [September 15, 2016, 12:12pm UTC](https://forum.ansible.com/t/i-got-error-dict-object-has-no-attribute-state-when-use-state-in-when/22556 "2016-09-15T12:12:36Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Andrey\_Rogovsky](https://avatars.discourse-cdn.com/v4/letter/a/9fc29f/32.png) [@Andrey\_Rogovsky](https://forum.ansible.com/u/Andrey_Rogovsky)\
**Post date:** [September 15, 2016, 12:12pm UTC](https://forum.ansible.com/t/i-got-error-dict-object-has-no-attribute-state-when-use-state-in-when/22556/1 "2016-09-15T12:12:36Z")

</div>

Hi, all!

There is result of execute my playbook:

# ansible-playbook test.yml

PLAY [ldap] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

…

TASK [freeipa-ds389d : Check if FreeIPA is configured] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
skipping: [[ds389.example.com](http://ds389.example.com)]  
ok: [[freeipa.example.com](http://freeipa.example.com)]

TASK [freeipa-ds389d : Setup FreeIPA Server] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
fatal: [[freeipa.example.com](http://freeipa.example.com)]: FAILED! =\> {“failed”: true, “msg”: “The conditional check ‘freeipa\_ipaconf.state.exist == False and inventory\_hostname == freeipa’ failed. The error was: error while evaluating conditional (freeipa\_ipaconf.state.exist == False and inventory\_hostname == freeipa): ‘dict object’ has no attribute ‘state’\n\nThe error appears to have been in ‘/root/new/freeipa-ds389d/tasks/main.yml’: line 41, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n- name: Setup FreeIPA Server\n ^ here\n”}  
fatal: [[ds389.example.com](http://ds389.example.com)]: FAILED! =\> {“failed”: true, “msg”: “The conditional check ‘freeipa\_ipaconf.state.exist == False and inventory\_hostname == freeipa’ failed. The error was: error while evaluating conditional (freeipa\_ipaconf.state.exist == False and inventory\_hostname == freeipa): ‘dict object’ has no attribute ‘state’\n\nThe error appears to have been in ‘/root/new/freeipa-ds389d/tasks/main.yml’: line 41, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n- name: Setup FreeIPA Server\n ^ here\n”}

NO MORE HOSTS LEFT \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
[WARNING]: Could not create retry file ‘test.retry’. [Errno 2] No such file or directory: ‘’

PLAY RECAP \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
[ds389.example.com](http://ds389.example.com) : ok=3 changed=0 unreachable=0 failed=1  
[freeipa.example.com](http://freeipa.example.com) : ok=5 changed=0 unreachable=0 failed=1

And there is a ansible script:

- name: Check if FreeIPA is configured  
tags:

- setup

- freeipa  
register: freeipa\_ipaconf  
always\_run: true  
stat:  
path: /etc/ipa/default.conf  
when: inventory\_hostname == freeipa

- name: Setup FreeIPA Server  
tags:

- setup

- freeipa  
become: true  
when: freeipa\_ipaconf.state.exist == False and inventory\_hostname == freeipa  
command: \>  
{{ freeipa\_install\_command }}  
{{ freeipa\_setup\_options }}

Can you help me resolve this issue?
