Duplicate dict key

412 views
Skip to first unread message

Josef Fortier

unread,
Jan 20, 2016, 6:43:50 PM1/20/16
to Ansible Project
Updating to 2.0 throws a new error (certainly not an unreasonable error) in a play I've used for a while:
found a duplicate dict key
I know I'm likely abusing behavior, but I'm hoping someone might offer an alternate approach :-)

At a high level, I'm looking to
1) take output from a command
2) run regex tests against it against a set of dictionary keys
3) on match, execute a command with a dict value

But some of the dict keys duplicate others

More specifically, I'm running SuSE and want to restart services on a zypper update when they show up as being "stale" (zypper -ps)
The major issue here, service names vary from version to version, and do not match precisely with the status output (zypper -ps)

I could possibly reverse the key value pairings, but there's still likely to be duplication.

I'd not be surprised if this wasn't working correctly before 2.0, but just silently discarding the duplication.

Thanks

Brian Coca

unread,
Jan 20, 2016, 6:49:00 PM1/20/16
to Ansible Project
that is exactly what was happening before 2.0, only the last value for
the key was used, the rest were discarded.

On Wed, Jan 20, 2016 at 6:43 PM, Josef Fortier <josef....@gmail.com> wrote:
> I'd not be surprised if this wasn't working correctly before 2.0, but just
> silently discarding the duplication.
>

i recommend this:

mykey: ['value1', 'value2', 'value3']

then match: "result in mykey" which you can use with map/select
filters if with_ loops are not enough
--
Brian Coca
Reply all
Reply to author
Forward
0 new messages