注册任务的结果,当我调试变量之后之后。我得到的价值是双引号,如"1234"
。如果我在另一个模块或任务中使用,它将变为[u'1234']
。使用注册变量ansible去除单引号
我已删除u和用括号替换字符。
如何摆脱单引号是ansible默认的。
Actual output : '1234'
expected output: 1234
剧本片断
- uri:
url: http://test/ws?Id=4a3d
method: GET
content_as_json: yes
password: admin
user: admin
validate_certs: no
return_content: yes
HEADER_Cookie: "{{login.set_cookie}}"
register: name
- debug: msg="{{ name.content | regex_findall('name=\"(\d+)\"') }}"
register: test
- uri:
url: "http://test/ws?name={{test.msg | replace('u','') | replace('[','') | replace(']','')}}"
method: GET
content_as_json: true
password: admin
user: admin
validate_certs: no
return_content: yes
HEADER_Cookie: "{{login.set_cookie}}"
我用int
也但返回0
{{test.msg | replace('u','') | replace('[','') | replace(']','') | int}}
URI模块输出:在
"<listResponse type=\"cust\" count=\"1\"><instance name=\"1234\" id=\"abcd\" customerRefId=\"xyz\" refId1=\"2345\" type=\"org\" enabled=\"true\" phone=\"\" fax=\"\" billingZip=\"\" billingAddress=\"\" billingCity=\"\" billingCountry=\"\" billingState=\"\" vendorId=\"1\" defaultEmail=\"pqr\" defaultContactName=\"wer\"/></listResponse>"
请添加您的playbook片段。我怀疑还有更好的办法。 –
添加了代码片段 –
为什么在这里使用debug?只需将'regex_findall'提供给下一个任务的url即可。 –