list seen as unicode, not sure why or how to correct

57 views
Skip to first unread message

Nicholas Britton

unread,
Aug 27, 2019, 4:32:11 PM8/27/19
to Ansible Project
I am building a list with output stored from a uri call:

  - name: Get hostgroup info
    uri
:
      url
: "{{baseurl}}views/host-groups?$query=hostGroup.storageDeviceId%20eq%20'{{ui}}'%20and%20hostGroup.hostGroupName%20in%20[{{vmc02}}]"
      method
: get
      validate_certs
: no
      headers
:
       
Authorization: "Session {{login.json.token}}"
       
Accept: "application/json"
       
Content-Type: "application/json"
   
register: hostgroups


 
- name: create list of hostgroups ids
    set_fact
:
      hostgroupnum_l
: "{{hostgroupnum_l}} + ['{{item.hostGroup.hostGroupNumber}}']"
    with_items
: "{{hostgroups.json.data}}"



But when the data is debuged it gives me this difference if i look at one item or multiple:


TASK [debug hostgroup list object] ******************************************************************************************************************************************************************
ok
: [localhost] => {
   
"msg": [
       
"10",
       
"11",
       
"12",
       
"13",
       
"14",
       
"15",
       
"16",
       
"9"
   
]
}


TASK
[debug hostgroupnumber output] *****************************************************************************************************************************************************************
ok
: [localhost] => {
   
"msg": "u'10'"
}


And this error when the next uri call attempts to use it, notice, how at the end i puts the list in unicode format, and the url does not know how to interpret that.
TASK [list sessions for 886000428027 - ams] *********************************************************************************************************************************************************
fatal
: [localhost]: FAILED! => {"changed": false, "connection": "close", "content": "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">\n<html><head>\n<title>400 Bad Request</title>\n</head><body>\n<h1>Bad Request</h1>\n<p>Your browser sent a request that this server could not understand.<br />\n</p>\n</body></html>\n", "content_length": "226", "content_type": "text/html; charset=iso-8859-1", "date": "Tue, 27 Aug 2019 20:26:28 GMT", "elapsed": 0, "msg": "Status code was 400 and not [200]: HTTP Error 400: Bad Request", "redirected": false, "server": "Apache", "status": 400, "url": "https://ip/ConfigurationManager/v1/views/lun-paths?$query=ldev.storageDeviceId%20eq%20'886000428027'%20and%20hostGroup.hostGroupNumber%20in%20'[u'10', u'11', u'12', u'13', u'14', u'15', u'16', u'9']'"}




Thoughts?






Kai Stian Olstad

unread,
Aug 27, 2019, 4:51:35 PM8/27/19
to ansible...@googlegroups.com
On 27.08.2019 22:32, Nicholas Britton wrote:
> And this error when the next uri call attempts to use it, notice, how at
> the end i puts the list in unicode format, and the url does not know how to
> interpret that.
> TASK [list sessions for 886000428027 - ams]
> *********************************************************************************************************************************************************
> fatal: [localhost]: FAILED! => {"changed": false, "connection": "close",
> "content": "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML
> 2.0//EN\">\n<html><head>\n<title>400 Bad
> Request</title>\n</head><body>\n<h1>Bad Request</h1>\n<p>Your browser sent
> a request that this server could not understand.<br
> />\n</p>\n</body></html>\n", "content_length": "226", "content_type": "text/html;
> charset=iso-8859-1", "date": "Tue, 27 Aug 2019 20:26:28 GMT", "elapsed": 0,
> "msg": "Status code was 400 and not [200]: HTTP Error 400: Bad Request",
> "redirected": false, "server": "Apache", "status": 400, "url": "https://ip/ConfigurationManager/v1/views/lun-paths?$query=ldev.storageDeviceId%20eq%20'886000428027'%20and%20hostGroup.hostGroupNumber%20in%20'[u'10',
> u'11', u'12', u'13', u'14', u'15', u'16', u'9']'"}

You can use the to_json filter to get "clean" json output.


--
Kai Stian Olstad

Nicholas Britton

unread,
Aug 27, 2019, 5:46:04 PM8/27/19
to Ansible Project
That provides me this:

TASK [debug number on array after unuiqe] ***********************************************************************************************************************************************************
ok: [localhost] => {
    "msg": "'\"10\"'"
}


how do i clean that up to only get the value 10 out of it?     

The end result i am expecting is for the list to look like:

'10','11','15'

Kai Stian Olstad

unread,
Aug 28, 2019, 3:20:03 AM8/28/19
to ansible...@googlegroups.com
On 27.08.2019 23:46, Nicholas Britton wrote:
> That provides me this:
>
> TASK [debug number on array after unuiqe]
> ***********************************************************************************************************************************************************
> ok: [localhost] => {
> "msg": "'\"10\"'"
> }
>
>
> how do i clean that up to only get the value 10 out of it?
>
> The end result i am expecting is for the list to look like:
>
> '10','11','15'

It's hard to give a solution since you have not provided all the
information we need.
But you can create a comma separated string with the join filter.

https://jinja.palletsprojects.com/en/2.10.x/templates/#join


--
Kai Stian Olstad

Nicholas Britton

unread,
Aug 28, 2019, 7:50:56 AM8/28/19
to ansible...@googlegroups.com
I tried to play with that some yesterday but did not have much luck. What can I provide you to help you help me?

--
You received this message because you are subscribed to a topic in the Google Groups "Ansible Project" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ansible-project/iSuFH-mE420/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/f3a327f758d28469bfaaef20b805e836%40olstad.com.

Nicholas Britton

unread,
Aug 28, 2019, 11:36:07 AM8/28/19
to Ansible Project
So i am trying to pull the hostgroupnumber since i need to use the list with a uri query that will use a in statement.     The api documentation shows that the the variable to search in the in statement, needs to look like: "'value1','value2','value3'"

Here is the set of tasks that i am using to generate the list variable:

---
 
- name: Set facts
    set_fact
:
      hostgroup_l
: []
      hostgroupnum_l
: []





 
- name: Get hostgroup info
    uri
:
#      url: "{{baseurl}}views/host-groups?$fields=hostGroup.hostGroupNumber&$query=hostGroup.storageDeviceId%20eq%20'{{ui}}'%20and%20hostGroup.hostGroupName%20in%20[{{vmc02}}]"

      url
: "{{baseurl}}views/host-groups?$query=hostGroup.storageDeviceId%20eq%20'{{ui}}'%20and%20hostGroup.hostGroupName%20in%20[{{vmc02}}]"
      method
: get
      validate_certs
: no
      headers
:
       
Authorization: "Session {{login.json.token}}"
       
Accept: "application/json"
       
Content-Type: "application/json"
   
register:
hostgroups


 
- name: debug hostgroups full
    debug
:
      msg
: "{{hostgroups}}"


 
- name: debug hostgroups
    debug
:
       msg
: "{{item.hostGroup.hostGroupNumber | pprint}}"
    with_items
: "{{hostgroups.json.data}}"


 
- name: create list of hostgroups
    set_fact
:
      hostgroup_l
: "{{hostgroup_l}} + ['{{item.hostGroup.hostGroupName}}']"
    with_items
: "{{hostgroups.json.data}}"



 
- name: create list of hostgroups ids
    set_fact
:
      hostgroupnum_l
: "{{hostgroupnum_l}} + ['{{item.hostGroup.hostGroupNumber}}']"
    with_items
: "{{hostgroups.json.data}}"





 
- name: debug number on array
    debug
:
      msg
: "{{hostgroupnum_l[0] | pprint}}"


 
- name: filter hostgroupnum_l to only unuiqe
    set_fact
:
      hostgroupnum_l
: "{{hostgroupnum_l | unique}}"


 
- name: debug number on array after unuiqe
    debug
:
      msg
: "{{hostgroupnum_l[0] |to_json| pprint}}"


 
- name: debug hostgroup list object
    debug
:
      msg
:  "{{hostgroup_l | unique}}"


 
- name: debug hostgroupnum list object
    debug
:
      msg
:  "{{hostgroupnum_l | unique}}"

Here is the base playbook that imports that task list and need to work with it:

---
- hosts: localhost
  connection
: local
  gather_facts
: false
  vars_prompt
:
  vars
:
    lunnuml
: []
  tasks
:
 
- name: Login - Import login play
    include_tasks
: tasks/login.include.yml


 
- name: get hostgroup ids
    include_tasks
: tasks/hostgroup.list.include.yml
#####################################
##  This is the section to changes ##
#####################################
 
- name: debug hostgroupnumber output
    debug
:
      msg
: "{{hostgroupnum_l[0] |  pprint}}"


 
- name: set fact test
    set_fact
:
      facttest
: "{{hostgroupnum_l | to_json  }}"
 
- name: fact-test debug
    debug
:
      msg
: "{{facttest[0] | pprint}}"


 
- name: list sessions for - ams
    uri
:
      url
: "{{baseurl}}views/lun-paths?$query=ldev.storageDeviceId%20eq%20'{{ui}}'%20and%20hostGroup.hostGroupNumber%20in%20'{{facttest}}'"

      method
: get
      validate_certs
: no
      headers
:
       
Authorization: "Session {{login.json.token}}"
       
Accept: "application/json"
       
Content-Type: "application/json"

   
register: luns


Here are the playbook results, shorted, and sanitized.
PLAY [localhost] ************************************************************************************************************************************************************************************


TASK
[Login - Import login play] ********************************************************************************************************************************************************************
included
: /home/nbritton/ansible/gts-core-storage-operations/hds/tasks/login.include.yml for localhost


TASK
[Login] ****************************************************************************************************************************************************************************************
ok
: [localhost]


TASK
[set facts] ************************************************************************************************************************************************************************************
ok
: [localhost]


TASK
[debug token] **********************************************************************************************************************************************************************************
ok
: [localhost] => {
   
"msg": "sometoken"
}


TASK
[debug sessionid] ******************************************************************************************************************************************************************************
ok
: [localhost] => {
   
"msg": "somesessionid"
}


TASK
[get hostgroup ids] ****************************************************************************************************************************************************************************
included
: /home/nbritton/ansible/gts-core-storage-operations/hds/tasks/hostgroup.list.include.yml for localhost


TASK
[Set facts] ************************************************************************************************************************************************************************************
ok
: [localhost]


TASK
[Get hostgroup info] ***************************************************************************************************************************************************************************
ok
: [localhost]


TASK
[debug hostgroups full] ************************************************************************************************************************************************************************
ok
: [localhost] => {
   
"msg": {

       
"changed": false,
       
"connection": "close",

       
"content_type": "application/json;charset=utf-8",
       
"cookies": {},
       
"cookies_string": "",
       
"date": "Wed, 28 Aug 2019 15:17:20 GMT",
       
"elapsed": 0,
       
"failed": false,
       
"json": {
           
"count": 32,
           
"data": [
               
{
                   
"hostGroup": {
                       
"hostGroupId": "CL7-A,10",
                       
"hostGroupName": "am1vmhost10",
                       
"hostGroupNumber": 10,
                       
"hostMode": "VMWARE_EX",
                       
"hostModeOptions": [
                           
54,
                           
63
                       
],
                       
"portId": "CL7-A",
                       
"storageDeviceId": "886000428027"
                   
}
               
},
               
{
                   
"hostGroup": {
                       
"hostGroupId": "CL7-A,11",
                       
"hostGroupName": "am1vmhost16",
                       
"hostGroupNumber": 11,
                       
"hostMode": "VMWARE_EX",
                       
"hostModeOptions": [
                           
54,
                           
63
                       
],
                       
"portId": "CL7-A",
                       
"storageDeviceId": "886000428027"
                   
}
               
},
                                   
           
],
           
"offset": 0,
           
"totalCount": 32
       
},
       
"msg": "OK (unknown bytes)",

       
"redirected": false,
       
"server": "Apache",

       
"status": 200,
       
"transfer_encoding": "chunked",
       
"url": "https://10.65.77.147:23451/ConfigurationManager/v1/views/host-groups?$query=hostGroup.storageDeviceId%20eq%20'886000428027'%20and%20hostGroup.hostGroupName%20in%20['am1vmhost9','am1vmhost10','am1vmhost11','am1vmhost12','am1vmhost13','am1vmhost14','am1vmhost15','am1vmhost16']"
   
}
}


TASK
[debug hostgroups] *****************************************************************************************************************************************************************************
ok
: [localhost] => (item={u'hostGroup': {u'hostGroupName': u'am1vmhost10', u'hostGroupId': u'CL7-A,10', u'portId': u'CL7-A', u'hostModeOptions': [54, 63], u'storageDeviceId': u'886000428027', u'hostMode': u'VMWARE_EX', u'hostGroupNumber': 10}}) => {
   
"msg": "10"
}
ok
: [localhost] => (item={u'hostGroup': {u'hostGroupName': u'am1vmhost16', u'hostGroupId': u'CL7-A,11', u'portId': u'CL7-A', u'hostModeOptions': [54, 63], u'storageDeviceId': u'886000428027', u'hostMode': u'VMWARE_EX', u'hostGroupNumber': 11}}) => {
   
"msg": "11"
}

ok
: [localhost] => (item={u'hostGroup': {u'hostGroupName': u'am1vmhost9', u'hostGroupId': u'CL8-B,9', u'portId': u'CL8-B', u'hostModeOptions': [54, 63], u'storageDeviceId': u'886000428027', u'hostMode': u'VMWARE_EX', u'hostGroupNumber': 9}}) => {
   
"msg": "9"
}


TASK
[create list of hostgroups] ********************************************************************************************************************************************************************
ok
: [localhost] => (item={u'hostGroup': {u'hostGroupName': u'am1vmhost10', u'hostGroupId': u'CL7-A,10', u'portId': u'CL7-A', u'hostModeOptions': [54, 63], u'storageDeviceId': u'886000428027', u'hostMode': u'VMWARE_EX', u'hostGroupNumber': 10}})
ok
: [localhost] => (item={u'hostGroup': {u'hostGroupName': u'am1vmhost16', u'hostGroupId': u'CL7-A,11', u'portId': u'CL7-A', u'hostModeOptions': [54, 63], u'storageDeviceId': u'886000428027', u'hostMode': u'VMWARE_EX', u'hostGroupNumber': 11}})

ok
: [localhost] => (item={u'hostGroup': {u'hostGroupName': u'am1vmhost9', u'hostGroupId': u'CL8-B,9', u'portId': u'CL8-B', u'hostModeOptions': [54, 63], u'storageDeviceId': u'886000428027', u'hostMode': u'VMWARE_EX', u'hostGroupNumber': 9}})


TASK
[create list of hostgroups ids] ****************************************************************************************************************************************************************
ok
: [localhost] => (item={u'hostGroup': {u'hostGroupName': u'am1vmhost10', u'hostGroupId': u'CL7-A,10', u'portId': u'CL7-A', u'hostModeOptions': [54, 63], u'storageDeviceId': u'886000428027', u'hostMode': u'VMWARE_EX', u'hostGroupNumber': 10}})
ok
: [localhost] => (item={u'hostGroup': {u'hostGroupName': u'am1vmhost16', u'hostGroupId': u'CL7-A,11', u'portId': u'CL7-A', u'hostModeOptions': [54, 63], u'storageDeviceId': u'886000428027', u'hostMode': u'VMWARE_EX', u'hostGroupNumber': 11}})

ok
: [localhost] => (item={u'hostGroup': {u'hostGroupName': u'am1vmhost9', u'hostGroupId': u'CL8-B,9', u'portId': u'CL8-B', u'hostModeOptions': [54, 63], u'storageDeviceId': u'886000428027', u'hostMode': u'VMWARE_EX', u'hostGroupNumber': 9}})


TASK
[debug number on array] ************************************************************************************************************************************************************************

ok
: [localhost] => {
   
"msg": "u'10'"
}



TASK
[filter hostgroupnum_l to only unuiqe] *********************************************************************************************************************************************************
ok
: [localhost]



TASK
[debug number on array after unuiqe] ***********************************************************************************************************************************************************
ok
: [localhost] => {
   
"msg": "'\"10\"'"
}



TASK
[debug hostgroup list object] ******************************************************************************************************************************************************************
ok
: [localhost] => {
   
"msg": [
       
"am1vmhost10",
       
"am1vmhost16",
       
"am1vmhost15",
       
"am1vmhost14",
       
"am1vmhost13",
       
"am1vmhost12",
       
"am1vmhost11",
       
"am1vmhost9"
   
]
}


TASK
[debug hostgroupnum list object] ***************************************************************************************************************************************************************
ok
: [localhost] => {
   
"msg": [

       
"10",
       
"11",
       
"12",
       
"13",
       
"14",
       
"15",
       
"16",
       
"9"
   
]
}


TASK
[debug hostgroupnumber output] *****************************************************************************************************************************************************************
ok
: [localhost] => {
   
"msg": "u'10'"
}



TASK
[set fact test] ********************************************************************************************************************************************************************************
ok
: [localhost]


TASK
[fact-test debug] ******************************************************************************************************************************************************************************
ok
: [localhost] => {
   
"msg": [
       
"[\"10\",",
       
"\"11\",",
       
"\"12\",",
       
"\"13\",",
       
"\"14\",",
       
"\"15\",",
       
"\"16\",",
       
"\"9\"]"
   
]

}


TASK
[list sessions for 886000428027 - ams] *********************************************************************************************************************************************************

fatal
: [localhost]: FAILED! => {"changed": false, "connection": "close", "content": "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">\n<html><head>\n<title>400 Bad Request</title>\n</head><body>\n<h1>Bad Request</h1>\n<p>Your browser sent a request that this server could not understand.<br />\n</p>\n</body></html>\n", "content_length": "226", "content_type": "text/html; charset=iso-8859-1", "date": "Wed, 28 Aug 2019 15:17:22 GMT", "elapsed": 0, "msg": "Status code was 400 and not [200]: HTTP Error 400: Bad Request", "redirected": false, "server": "Apache", "status": 400, "url": "https://10.65.77.147:23451/ConfigurationManager/v1/views/lun-paths?$query=ldev.storageDeviceId%20eq%20'886000428027'%20and%20hostGroup.hostGroupNumber%20in%20'[\"10\", \"11\", \"12\", \"13\", \"14\", \"15\", \"16\", \"9\"]'"}




Does that help more?




On Wednesday, August 28, 2019 at 6:50:56 AM UTC-5, Nicholas Britton wrote:
I tried to play with that some yesterday but did not have much luck. What can I provide you to help you help me?

On Wed, Aug 28, 2019, 2:20 AM Kai Stian Olstad <ansible-project+list@olstad.com> wrote:
On 27.08.2019 23:46, Nicholas Britton wrote:
> That provides me this:
>
> TASK [debug number on array after unuiqe]
> ***********************************************************************************************************************************************************
> ok: [localhost] => {
>     "msg": "'\"10\"'"
> }
>
>
> how do i clean that up to only get the value 10 out of it?
>
> The end result i am expecting is for the list to look like:
>
> '10','11','15'

It's hard to give a solution since you have not provided all the
information we need.
But you can create a comma separated string with the join filter.

https://jinja.palletsprojects.com/en/2.10.x/templates/#join


--
Kai Stian Olstad

--
You received this message because you are subscribed to a topic in the Google Groups "Ansible Project" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ansible-project/iSuFH-mE420/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ansible-project+unsubscribe@googlegroups.com.

Werner Flamme

unread,
Aug 29, 2019, 5:07:53 AM8/29/19
to ansible...@googlegroups.com
Nicholas Britton schrieb am 28.08.19 um 17:36:
> url:
> "{{baseurl}}views/lun-paths?$query=ldev.storageDeviceId%20eq%20'{{ui}}'%20and%20hostGroup.hostGroupNumber%20in%20'{{facttest}}'"
> method: get

does it work if you use ...in%20'{{facttest|pow(1)}}'" ? This should
translate facttest into a number.

HTH, Werner

--


Kai Stian Olstad

unread,
Aug 29, 2019, 7:46:15 AM8/29/19
to ansible...@googlegroups.com
On 28.08.2019 17:36, Nicholas Britton wrote:
> So i am trying to pull the hostgroupnumber since i need to use the list
> with a uri query that will use a in statement. The api
> documentation
> shows that the the variable to search in the in statement, needs to
> look
> like: "'value1','value2','value3'"

After reading thru everything I think it boils down to this.

You have list on int's
[10, 11, 12, 13, 14, 15, 16, 9]

that you need to be a string looking like

'10','11','12','13','14','15','16','9'

And since it's going to be used in a url you probably need to url encode
it too.


> Here is the set of tasks that i am using to generate the list variable:
>
> ---
> - name: Set facts
> set_fact:
> hostgroup_l: []
> hostgroupnum_l: []

You don't need this if you do my proposed changes bellow.


> - name: create list of hostgroups
> set_fact:
> hostgroup_l: "{{hostgroup_l}} +
> ['{{item.hostGroup.hostGroupName}}']"
> with_items: "{{hostgroups.json.data}}"

This is a lot faster

- name: create list of hostgroups
set_fact:
hostgroup_l: "{{ hostgroups.json.data |
map(attribute='hostGroup.hostGroupName') | list }}"


> - name: create list of hostgroups ids
> set_fact:
> hostgroupnum_l: "{{hostgroupnum_l}} +
> ['{{item.hostGroup.hostGroupNumber}}']"
> with_items: "{{hostgroups.json.data}}"

- name: create list of hostgroups ids
set_fact:
hostgroupnum_l: "{{ hostgroups.json.data |
map(attribute='hostGroup.hostGroupNumber' | list }}"


So to get this to a string you can do this

- name: String
set_fact:
hostgrpnum_s: >-
{{ "'" ~ hostgroupnum_l | join("','") ~ "'" }}

Here I'm using muliline YAML so I avoid problem with qoutes since you
don't need qoutes at the start and end.

And you can use urlencode filter to get proper url format.

--
Kai Stian Olstad

Nicholas Britton

unread,
Aug 29, 2019, 9:48:04 AM8/29/19
to Ansible Project
Thank you.   I see what your doing there and why.    That makes since to me.

The part i dont follow 100% is the string part.   Would you mind breaking that down for me?     I also notice when i put that in my task list that the coloars for the next task change, does that indicate a problem?       

2019-08-29_8-31-34.png

I also notice the string puts a space at the end, and if i create two test stings one without the space and one with, it works without but not with:

    test1: "'10','11','12','13','14','15','16','9'"
    test2
: "'10','11','12','13','14','15','16','9' "

TASK [String] ***************************************************************************************************************************************************************************************
ok
: [localhost]


TASK
[debug - string] *******************************************************************************************************************************************************************************
ok
: [localhost] => {
   
"msg": "'10','11','12','13','14','15','16','9' "
}



I also tried to add a replace filter in a couple of different ways, but they all seem to have a quoting problem that i am not seeing:

  - name: String
    set_fact
:
      hostgrpnum_s
: >-
       
{{ "'" ~ hostgroupnum_l | join("','") ~ "'" }}



 
- name: debug - string
    debug
:
      msg
: "{{hostgrpnum_s | replace(" ", "") }}"



The offending line appears to be:

    debug:
      msg: "{{hostgrpnum_s | replace(" ", "") }}"
                                       ^ here

Vladimir Botka

unread,
Aug 29, 2019, 10:13:50 AM8/29/19
to Nicholas Britton, ansible...@googlegroups.com
On Tue, 27 Aug 2019 13:32:11 -0700 (PDT)
Nicholas Britton <britton....@gmail.com> wrote:

> I am building a list with output stored from a uri call:
> [...]
> - name: create list of hostgroups ids
> set_fact:
> hostgroupnum_l: "{{hostgroupnum_l}} +
> ['{{item.hostGroup.hostGroupNumber}}']"
> with_items: "{{hostgroups.json.data}}"

Try this:

- name: create list of hostgroups ids
set_fact:
hostgroupnum_l: "{{ hostgroupnum_l|default([]) +
[item.hostGroup.hostGroupNumber] }}"
loop: "{{ hostgroups.json.data }}"

Cheers,

-vlado

Kai Stian Olstad

unread,
Aug 29, 2019, 10:23:50 AM8/29/19
to ansible...@googlegroups.com
On 29.08.2019 15:48, Nicholas Britton wrote:
> Thank you. I see what your doing there and why. That makes since
> to me.
>
> The part i dont follow 100% is the string part. Would you mind
> breaking
> that down for me? I also notice when i put that in my task list
> that
> the coloars for the next task change, does that indicate a problem?

I can try, hopefully is understandable.


The join filter take a list and join each element in the list with a
string.
So the list is joined by the string ','

The list
[10, 11, 12]

becomes with join("','")

10','11','12

Tilde, ~ , is string concatenation in Jinja so it will be

"'" ~ "10','11','12" ~ "'"

That becomes

'10','11','12'

The color change is because the syntax highlighting is confused by all
the quotes and multiline YAML, but there is no problem.
It looks like you are using vim, if you install this plugin it will
handle this without problem.
https://github.com/pearofducks/ansible-vim


> [image: 2019-08-29_8-31-34.png]
> I also notice the string puts a space at the end, and if i create two
> test
> stings one without the space and one with, it works without but not
> with:
>
> test1: "'10','11','12','13','14','15','16','9'"
> test2: "'10','11','12','13','14','15','16','9' "

The space I guess is because you have a space after }} in the set_fact
task.
You can turn on highlighting of trailing whitespace in vim so they are
more easily spotted.


> TASK [String]
> ***************************************************************************************************************************************************************************************
> ok: [localhost]
>
>
> TASK [debug - string]
> *******************************************************************************************************************************************************************************
> ok: [localhost] => {
> "msg": "'10','11','12','13','14','15','16','9' "
> }
>
>
>
> I also tried to add a replace filter in a couple of different ways, but
> they all seem to have a quoting problem that i am not seeing:
>
> - name: String
> set_fact:
> hostgrpnum_s: >-
> {{ "'" ~ hostgroupnum_l | join("','") ~ "'" }}

The space is at the end of this line.


--
Kai Stian Olstad

Nicholas Britton

unread,
Aug 29, 2019, 11:48:01 AM8/29/19
to Ansible Project
Thank you!   That helped me connect the dots.     I found the extra space and its working like a champ.  Thank  you again!
Reply all
Reply to author
Forward
0 new messages