Hi,

I have a variable which is a list (sourced from registering the response
from a 3rd party module). In that list, each item is a dict, as follows:

[
  {'policyid': '1009', 'other': 'content'},
  {'policyid': '2019', 'other': 'content'},
  {'policyid': '1024', 'other': 'content'},
  {'policyid': '1000', 'other': 'content'},
  {'policyid': '8732', 'other': 'content'},
  {'policyid': '1012', 'other': 'content'}
]

I have some code that works locally on my machine:

- name: sort policy
  set_fact:
    desired_policy: |
      [
        {% for policy in fwpolicy.meta.results | sort(attribute='policyid')
%}
          {
            'rule': '{{ policy.policyid }}',
            'after': '{{ (loop.previtem | default({}) )['policyid'] |
default(0) }}',
            'before': '{{ (loop.nextitem | default({}) )['policyid'] |
default(0) }}'
          },
        {% endfor %}
      ]

When I run this on my machine, I get the following list:

[
  {'policyid': '1000', 'after': 0, 'before': 1009},
  {'policyid': '1009' , 'after': 1000, 'before': 1012},
  {'policyid': '1012' , 'after': 1009, 'before': 1024},
  {'policyid': '1024' , 'after': 1012, 'before': 2019},
  {'policyid': '2019' , 'after': 1024, 'before': 8732},
  {'policyid': '8732' , 'after': 2019, 'before': 0}
]

On my colleague's machine (and on AWX for that matter), I get:

[
  {'policyid': '1000', 'after': 0, 'before': 0},
  {'policyid': '1009' , 'after': 0, 'before': 0},
  {'policyid': '1012' , 'after': 0, 'before': 0},
  {'policyid': '1024' , 'after': 0, 'before': 0},
  {'policyid': '2019' , 'after': 0, 'before': 0},
  {'policyid': '8732' , 'after': 0, 'before': 0}
]

Am I doing something wrong, and should I be doing something differently?
--
Jon "The Nice Guy" Spriggs
@jontheniceguy everywhere...
https://jon.sprig.gs

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CAOrCWesZBGwYfnXq17YRmZ9gAiUrGxW0omHxSN%2BhrhEc5DYP_g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to