Reputation: 87
I have a task that add Gnome favorites for each user:
users:
- name: username
email: [email protected]
favorites: "'pk1.desktop', 'pk2.desktop', 'pk3.desktop', pk4.desktop'"
- name: "[DCONF] Add favorites"
dconf:
key: /org/gnome/shell/favorite-apps
value: "[{{ item.favorites }}]"
state: present
become: yes
become_user: "{{ item.name }}"
with_items: "{{ users }}"
I get this error:
[WARNING]: The value ['pk1.desktop', 'pk2.desktop', 'pk3.desktop', pk4.desktop'] (type list) in a string field was converted to u"['pk1.desktop', 'pk2.desktop', 'pk3.desktop', pk4.desktop']" (type string). If this does
not look like what you expect, quote the entire value to ensure it does not change.
How could I fix that?
Also, how could I transform this so that it looks like this:
users:
- name: username
email: [email protected]
favorites:
- 'pk1.desktop'
- 'pk2.desktop'
- 'pk3.desktop'
- 'pk4.desktop'
the reason being that I have a lot of those favorites, so that would be easier for me to handle like this, and also because I want to learn how to do that ;)
Upvotes: 2
Views: 4400
Reputation: 44615
I cannot reproduce your warning message (ansible 2.9.9). Note you have a single quote missing on the last value.
Meanwhile, since you want to transition to declaring your values in a list for simplicity, the following should allow you to do so and fix your issue all together.
---
- name: Set favs
hosts: somehost
remote_user: someuser
vars:
users:
- name: username
email: [email protected]
favorites:
- pk1.desktop
- pk2.desktop
- pk3.desktop
- pk4.desktop
tasks:
- name: "[DCONF] Add favorites"
dconf:
key: /org/gnome/shell/favorite-apps
value: "{{ item.favorites | string }}"
state: present
become: yes
become_user: "{{ item.name }}"
with_items: "{{ users }}"
Upvotes: 3