# fix idempotence for this command

**URL:** <https://forum.ansible.com/t/fix-idempotence-for-this-command/35239>\
**Category:** Ansible Project\
**Created:** [May 27, 2021, 2:02pm UTC](https://forum.ansible.com/t/fix-idempotence-for-this-command/35239 "2021-05-27T14:02:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nicola\_L](https://avatars.discourse-cdn.com/v4/letter/n/9dc877/32.png) [@Nicola\_L](https://forum.ansible.com/u/Nicola_L)\
**Post date:** [May 27, 2021, 2:02pm UTC](https://forum.ansible.com/t/fix-idempotence-for-this-command/35239/1 "2021-05-27T14:02:23Z")

</div>

Hi,  
this task breaks the idempotence of my role:

- name: Set directories permissions for production installation  
command: find /opt/tomcat -type d -exec chmod -c 2750 {} ;  
register: find\_chmod\_result  
changed\_when: ‘find\_chmod\_result.stdout | length \> 0’

The command is selecting all the folders (and not the files) located under /opt/tomcat and it applies them the permissions 2750.

Is there a way to express the same thing without breaking the idempotence?

Nicola

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [May 27, 2021, 2:03pm UTC](https://forum.ansible.com/t/fix-idempotence-for-this-command/35239/2 "2021-05-27T14:03:56Z")

</div>

Instead of running the find command via `command`, switch to using the `find` module, register the result, then use the `file` module, looping the previous results, to set permissions on the directories.

---

<div class="post-metadata">

**Author:** ![Nicola\_L](https://avatars.discourse-cdn.com/v4/letter/n/9dc877/32.png) [@Nicola\_L](https://forum.ansible.com/u/Nicola_L)\
**Post date:** [May 27, 2021, 3:56pm UTC](https://forum.ansible.com/t/fix-idempotence-for-this-command/35239/3 "2021-05-27T15:56:49Z")

</div>

Thank you!! That’s indeed the solution!  
Now it looks like this:

- name: Set directories permissions - select  
find:  
paths: "/opt/tomcat  
file\_type: directory  
register: find\_chmod\_result

- name: Set directories permissions - apply  
file:  
path: “{{ item.path }}”  
owner: “{{ tomcat\_user }}”  
group: “{{ tomcat\_group }}”  
mode: ‘02775’  
loop: “{{ find\_chmod\_result.files }}”

Nicola
