List Ansible:将带有unicode的列表转换为字符串列表(并进行比较)

List Ansible:将带有unicode的列表转换为字符串列表(并进行比较),list,ansible,diff,python-unicode,ansible-awx,List,Ansible,Diff,Python Unicode,Ansible Awx,我创建了一个包含所有可用组主机的列表。 但是当我打印列表时,它包含unicode字符u'text'而不是“text” 是否有任何有效的方法删除/转换此文件。 我在网上看了其他例子,但没有成功 使用unicode字符的当前(错误)输出: ok: [server.name] => { "msg": " [u'all', u'coaster', u'aes', u'curo, u'dert', u'tomcatdeploy', u'implus-app', u'domain-top', u'tp

我创建了一个包含所有可用组主机的列表。 但是当我打印列表时,它包含unicode字符u'text'而不是“text” 是否有任何有效的方法删除/转换此文件。 我在网上看了其他例子,但没有成功

使用unicode字符的当前(错误)输出:

ok: [server.name] => {
"msg": " [u'all', u'coaster', u'aes', u'curo, u'dert', u'tomcatdeploy', u'implus-app', u'domain-top', u'tp-general', u'cdaes01', u'dicco-acc' .....
这应该具有与以下列表相同的格式。因为我想把它们和diff进行比较。 列表中的值本身不同,但格式应如下所示:

ok: [server.name] => {
"msg": [
    "tools", 
    "tools-api", 
    "adr-app", 
    "adr-app-e2j", 
    "aec", 
    "aec-copy", 
    "aes", 
    "aes1", 
    "aes2", 
    "aes3", 
    "ais", 
    "apiman", 
    "apiman-gateway-poc", 
    "apiman-manager", 
    "apiman-manager-poc", 
    "apollo-beheer-aangiftes", ...
目前,我正在使用以下代码获取列表:

- name: register groups
  set_fact:
    inventory_groups: []  # empty list
    inventory_group_keys: "{{ groups.keys() |to_yaml}}" #|list

- name: clean white spaces from list
  set_fact:
    inventory_groups: "{{ inventory_groups}} + ['{{item.strip()}}']"
  with_items: "{{inventory_group_keys[1:-2].split(',')}}"

- name: print inventory_groups from local host for debugging
  debug:
    msg: " {{ inventory_groups }}"
第二个列表是使用AWXAPI获取的。 还请注意,出于某种原因,[括号前面似乎有一个“”。 如下所示:

"msg": " [u'all',....
这不在第一个列表中。知道为什么吗?我想这会给以后比较它们带来问题。
我创建列表的方法是相同的。

这最终解决了我的大部分问题

- name: print list
  debug:
    msg: "{{ groups | list }}"
其中给出了以下列表:

ok: [server.name] => {
    "msg": [
        "all", 
        "coster", 
        "ius1", 
        "curo", 
        "derti", 
        "tomcatdeploy", 
        "implus-app", 
        "domain", 
        "tpgeneral", 
        "cdaes", 
        "diccop-acc", 
        "cdaes", 
         .... 

这最终解决了我的大部分问题

- name: print list
  debug:
    msg: "{{ groups | list }}"
其中给出了以下列表:

ok: [server.name] => {
    "msg": [
        "all", 
        "coster", 
        "ius1", 
        "curo", 
        "derti", 
        "tomcatdeploy", 
        "implus-app", 
        "domain", 
        "tpgeneral", 
        "cdaes", 
        "diccop-acc", 
        "cdaes", 
         ....