# Able to change execution order of with\_items?

**URL:** <https://forum.ansible.com/t/able-to-change-execution-order-of-with-items/25666>\
**Category:** Ansible Project\
**Created:** [October 2, 2017, 9:53pm UTC](https://forum.ansible.com/t/able-to-change-execution-order-of-with-items/25666 "2017-10-02T21:53:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![John\_Harmon](https://avatars.discourse-cdn.com/v4/letter/j/edb3f5/32.png) [@John\_Harmon](https://forum.ansible.com/u/John_Harmon)\
**Post date:** [October 2, 2017, 9:53pm UTC](https://forum.ansible.com/t/able-to-change-execution-order-of-with-items/25666/1 "2017-10-02T21:53:47Z")

</div>

I have the following in my playbook, and when it writes the contents it writes in this format:

ServerA:  
sudoers

ServerB:  
sudoers

ServerA:  
other\_users

ServerB:  
other\_users.

I would like the following format if possible:

ServerA  
sudoers

ServerA  
other\_users

ServerB  
sudoers

ServerB  
other\_users

`

- name: Write users  
lineinfile:  
dest: “/tmp/users.txt”  
line: “HOST: {{ansible\_nodename}}\n{{item}}\n\n”  
insertafter: EOF  
create: yes  
state: present  
delegate\_to: localhost  
with\_items:
- “{{sudoers.stdout\_lines|to\_nice\_json}}”
- “{{other\_users.stdout\_lines|to\_nice\_json}}”  
notify:
- email
- cleanup

`

---

<div class="post-metadata">

**Author:** ![John\_Harmon](https://avatars.discourse-cdn.com/v4/letter/j/edb3f5/32.png) [@John\_Harmon](https://forum.ansible.com/u/John_Harmon)\
**Post date:** [October 2, 2017, 10:35pm UTC](https://forum.ansible.com/t/able-to-change-execution-order-of-with-items/25666/2 "2017-10-02T22:35:33Z")

</div>

I have a way to do this, but am looking for improvements.

If I change the “forks =” setting in the ansible.cfg file, then this works exactly the way I want it to. I don’t mind creating a custom ansible.cfg file (ie ansible\_1fork.cfg), but I don’t yet see a way to call the playbook with the custom.cfg (I will be calling it via cron).  
I tried “serial: 1”, but I get too many emails… I want just the one email.

Any ideas?

---

<div class="post-metadata">

**Author:** ![John\_Harmon](https://avatars.discourse-cdn.com/v4/letter/j/edb3f5/32.png) [@John\_Harmon](https://forum.ansible.com/u/John_Harmon)\
**Post date:** [October 2, 2017, 10:50pm UTC](https://forum.ansible.com/t/able-to-change-execution-order-of-with-items/25666/3 "2017-10-02T22:50:41Z")

</div>

I have it… kind of ugly, but it works. ANSIBLE\_CONFIG is an environment variable I can work with. I have to export it to get it to work. I set it to what I need for this one playbook, and then set it back to the default after it is complete.

1 2 1 1-12/3 \* export ANSIBLE\_CONFIG=“/etc/ansible/ansible\_1fork.cfg”; ansible-playbook /playbooks/fetch\_server\_admins/fetch\_server\_admins.yml -e “host=myservers”; export ANSIBLE\_CONFIG=“/etc/ansible/ansible.cfg”
