# Ansible Set Operations Do Not Preserve List Order

DevFeed: [Ansible Set Operations Do Not Preserve List Order](<https://devfeed.tech/articles/ansible-set-operations-do-not-preserve-list-order-10941.md>)

Original publisher: [Read original article](<https://blog.ipspace.net/2024/02/ansible-set-operations/>)

Published: 2024-02-26T06:08:00Z

Content type: tutorial

Language: en

Sources: [ipSpace.net blog](<https://devfeed.tech/sources/ipspace-net-blog.md>)

Topics: [Ansible](<https://devfeed.tech/topics/ansible.md>), [configuration](<https://devfeed.tech/topics/configuration.md>), [Python](<https://devfeed.tech/topics/python.md>), [Deployment](<https://devfeed.tech/topics/deployment.md>)

Tags: [ansible](<https://devfeed.tech/tags/ansible.md>), [collections](<https://devfeed.tech/tags/collections.md>), [configuration](<https://devfeed.tech/tags/configuration.md>), [deployment](<https://devfeed.tech/tags/deployment.md>), [python](<https://devfeed.tech/tags/python.md>)

## AI overview

This article explains why an Ansible intersect filter can produce module lists in a non-deterministic order. The filter converts its arguments to Python sets, whose elements are unordered, so configuration modules such as DHCP and OSPF may be applied in the wrong order. It presents a when condition as a workaround.

## Source excerpt

Here's another Ansible quirk, this time caused by Python set behavior. When I created the initial device configuration deployment playbook in netlab, I wanted to: Be able to specify a list of modules to provision.1 Provision just the modules used in the topology and specified in the list of modules. This allows you to use netlab initial to deploy all configuration modules used in a lab topology or netlab initial -m ospf to deploy just OSPF while surviving netlab initial -m foo (which would do nothing). Read more ...