I am trying to sort a list when setting a fact in Ansible as follows:
This works when I run it from the command line, but when I do this within Ansible Tower, I get the following error:
Unexpected templating type error occurred on ({{ ansible_facts.packages|dict2items|sort }}): ‘<’ not supported between instances of ‘dict’ and ‘dict’
I know this isn’t a Tower list, but would anyone have any idea why this would work in the Ansible CLI but not in Tower?
Thanks,
             
            
              
            
           
          
            
              
                sivel  
              
                  
                    October 19, 2021,  5:31pm
                   
                  2 
               
             
            
              I’d recommend that you use dictsort instead of dict2items It achieves the goal very similarly, but sorts by default, and would avoid the error you are getting.
The biggest difference is instead of having item.key and item.value, you have item.0 and item.1.
https://jinja.palletsprojects.com/en/latest/templates/#jinja-filters.dictsort 
             
            
              
            
           
          
            
            
              So if I set the fact as follows:
name: Set package facts 
 
How would I traverse that in my template?:
{% for v in hostvars[i][‘packages’] %}
Thanks,
             
            
              
            
           
          
            
              
                sivel  
              
                  
                    October 19, 2021,  6:21pm
                   
                  4 
               
             
            
              from a quick glance, it looks like you would change v.value to v.1
             
            
              
            
           
          
            
            
              OK, that took care of it. Worked great! I appreciate the timely response!
Thanks,