# do\_dictsort() got an unexpected keyword argument 'reverse'

**URL:** <https://forum.ansible.com/t/do-dictsort-got-an-unexpected-keyword-argument-reverse/26571>\
**Category:** Ansible Project\
**Created:** [January 26, 2018, 3:35pm UTC](https://forum.ansible.com/t/do-dictsort-got-an-unexpected-keyword-argument-reverse/26571 "2018-01-26T15:35:33Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Martin\_Cigorraga](https://avatars.discourse-cdn.com/v4/letter/m/f1d935/32.png) [@Martin\_Cigorraga](https://forum.ansible.com/u/Martin_Cigorraga)\
**Post date:** [January 26, 2018, 3:35pm UTC](https://forum.ansible.com/t/do-dictsort-got-an-unexpected-keyword-argument-reverse/26571/1 "2018-01-26T15:35:33Z")

</div>

Hi everyone,

We are using a Jinja2 template to populate a configuration file, based on the information Ansible feeds it on runtime:

`

### Main Processes

{% for k, v in some\_conf | dictsort() %}  
  
cmdline -c /etc/some\_tool/some\_agent-{{ k }}.conf -o /var/log/some\_tool/some\_agent.log  
  
{% endfor %}

`

We get a predictable output thanks to using dictsort():

`% cat /etc/some_tool/some_agent.conf <process> cmdline -c some_agent-AAA.conf -o /var/log/some_tool/some_agent.log </process> <process> cmdline -c some_agent-BBB.conf -o /var/log/some_tool/some_agent.log </process>`

Thing is we need in the above configuration file that some\_agent-BBB.conf is placed _before_ than some\_agent-AAA.conf; for that matter I introduced the **reverse=True** argument to dictsort():

`

### Main Processes

{% for k, v in some\_conf | dictsort( **reverse=True** ) %}  
  
cmdline -c /etc/some\_tool/some\_agent-{{ k }}.conf -o /var/log/some\_tool/some\_agent.log  
  
{% endfor %}  
`

When tested using Yasha ([GitHub - kblomqvist/yasha: A command-line tool to render Jinja templates for great good](https://github.com/kblomqvist/yasha)), the output is the expected one:

`% cat /etc/some_tool/some_agent.conf <process> cmdline -c some_agent-BBB.conf -o /var/log/some_tool/some_agent.log </process> <process> cmdline -c some_agent-AAA.conf -o /var/log/some_tool/some_agent.log </process>`

However, when running the playbook, Ansible complains and stops execution, showing the error message I put on the subject of this email: **do\_dictsort() got an unexpected keyword argument ‘reverse’**

Why’re running **ansible 2.1.1.0**.  
Thanks!

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [January 26, 2018, 3:42pm UTC](https://forum.ansible.com/t/do-dictsort-got-an-unexpected-keyword-argument-reverse/26571/2 "2018-01-26T15:42:57Z")

</div>

the `reverse` argument for `dictsort` was not added until jinja2 v2.10 which was released on Nov 8, 2017

Ansible has a dependency on jinja2, but does not dictate which specific version you should have installed. To get access to that feature you will need to upgrade your version of jinja2

You may be able to use the `reverse` filter instead, but I have not tested: [http://jinja.pocoo.org/docs/dev/templates/#reverse](http://jinja.pocoo.org/docs/dev/templates/#reverse)

---

<div class="post-metadata">

**Author:** ![Martin\_Cigorraga](https://avatars.discourse-cdn.com/v4/letter/m/f1d935/32.png) [@Martin\_Cigorraga](https://forum.ansible.com/u/Martin_Cigorraga)\
**Post date:** [January 26, 2018, 4:12pm UTC](https://forum.ansible.com/t/do-dictsort-got-an-unexpected-keyword-argument-reverse/26571/3 "2018-01-26T16:12:48Z")

</div>

Hi Matt,

Thanks for your thorough and quick answer. We’ll look into it and let you know the result.

---

<div class="post-metadata">

**Author:** ![Martin\_Cigorraga](https://avatars.discourse-cdn.com/v4/letter/m/f1d935/32.png) [@Martin\_Cigorraga](https://forum.ansible.com/u/Martin_Cigorraga)\
**Post date:** [February 14, 2018, 1:36am UTC](https://forum.ansible.com/t/do-dictsort-got-an-unexpected-keyword-argument-reverse/26571/4 "2018-02-14T01:36:12Z")

</div>

Matt,

I can’t share the details as it wasn’t me the one who made the implementation, but we were able to adapt the Jinja2 2.10 filter plugin by converting it to an Ansible v2 filter plugin.

Cheers
