# Looking for generic execute "once-only" practise for Automations

**URL:** <https://forum.ansible.com/t/looking-for-generic-execute-once-only-practise-for-automations/36613>\
**Category:** Ansible Developer\
**Created:** [May 10, 2022, 8:47pm UTC](https://forum.ansible.com/t/looking-for-generic-execute-once-only-practise-for-automations/36613 "2022-05-10T20:47:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![user29032902](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/user29032902/32/228_2.png) [@user29032902](https://forum.ansible.com/u/user29032902)\
**Post date:** [May 10, 2022, 8:47pm UTC](https://forum.ansible.com/t/looking-for-generic-execute-once-only-practise-for-automations/36613/1 "2022-05-10T20:47:28Z")

</div>

Hi Guys,

We use Ansible to perform a number of integrations with third-party systems.  
e.g.

1. Sync this user’s information from System X to System Y.
2. If the user is a member of AD group “LicenseManagement”, send an email to Person Z.
3. etc.

In most of our integrations we need to execute the action only once per user. There are a growing number of integrations where we can’t connect to their platform, and so I need a native way within Ansible to track whether the automation has already been actioned (for the subject user).

I am putting this out here to see if anyone has come across this before. And if there are any native things we can do within Red Hat Ansible Tower to track these sorts of states.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [May 11, 2022, 5:33pm UTC](https://forum.ansible.com/t/looking-for-generic-execute-once-only-practise-for-automations/36613/2 "2022-05-11T17:33:06Z")

</div>

Many ways, just an example:  
- in a handler update a host\_vars/\<sytemY\>.yml with the list of users  
already synced, notify when sync tasks run/change  
- add to sync role/block/tasks a conditional based on the variable  
cdreated `when: username not in already_processed_users`

---

<div class="post-metadata">

**Author:** ![user29032902](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/user29032902/32/228_2.png) [@user29032902](https://forum.ansible.com/u/user29032902)\
**Post date:** [May 11, 2022, 5:45pm UTC](https://forum.ansible.com/t/looking-for-generic-execute-once-only-practise-for-automations/36613/3 "2022-05-11T17:45:40Z")

</div>

Hey Brian,

I like the idea of using **host\_vars**.

Within the playbook I will need to update **host\_vars** based on the outcome of the job. For example, after emailing user `jdoe`​, update variable `emailed_users`​. That way, when the job runs again a few minutes later, I want the second job to know what work was completed on the first job so not to email `jdoe`​ again. Hopefully that example makes sense.

Is there a way within the playbook that I can add `jdoe`​ to `emailed_users`​​, and record that change so that the variable change persists across multipe Ansible Tower jobs?
