英文:
How to remove prefix from ansible output
问题
- name: "重新索引 {{item}} 到本地服务器"
ignore_errors: yes
uri:
url: "{{proto}}://{{new_server}}:{{es_api_port}}/_reindex?wait_for_completion=false"
method: POST
headers:
Authorization: '基本认证=='
body:
source :
index: "{{ item }}"
dest:
index: "{{ item.split('reindex-') | to_nice_json}}"
body_format: json
with_items:
- reindex-abc-def-ghi--2020-08-31
- reindex-abc-def-ghi--2020-08-30
输出结果是:
"module_args": {
"attributes": null,
"body": {
"dest": {
"index": "abc-def-ghi-2020-08-31"
},
"source": {
"index": "reindex-abc-def-ghi--2020-08-31"
}
},
所以,在输出中,dest
显示为 "abc-def-ghi-2020-08-31"
。
英文:
I have to parse a string in a ansible but when I try to use regex , it creates array.
here is the code
- name: "Reindexing {{item}} to local server "
ignore_errors: yes
uri:
url: "{{proto}}://{{new_server}}:{{es_api_port}}/_reindex?wait_for_completion=false"
method: POST
headers:
Authorization: 'Basic auth=='
body:
source :
index: "{{ item }}"
dest:
index: "{{ item.split('reindex-') | to_nice_json}}"
body_format: json
with_items:
- reindex-abc-def-ghi--2020-08-31
- reindex-abc-def-ghi--2020-08-30
output is:
"module_args": {
"attributes": null,
"body": {
"dest": {
"index": "[\n \"\",\n \"abc-def-ghi-2020-08-31\"\n]"
},
"source": {
"index": "reindex-abc-def-ghi--2020-08-31"
}
},
so, In output, dest is showing [\n "",\n "abc-def-ghi-2020-08-31"\n]. I am just looking for this "abc-def-ghi-2020-08-31"
Thanks!
答案1
得分: 1
In output, dest is showing ["", "abc-def-ghi-2020-08-31"].
That's because you're passing the output of item.split()
to to_nice_json
, which is for nicely formatting (e.g., with multiple lines and indentation) JSON documents. Why are you using that here?
The result of item.split('reindex-')
is a two-element list, ["", "abc-def-ghi--2020-08-30"]. If you just want the second element, you can write:
dest:
index: "{{ item.split('reindex').1 }}"
英文:
> In output, dest is showing [\n "",\n "abc-def-ghi-2020-08-31"\n].
That's because you're passing the output of item.split()
to to_nice_json
, which is for nicely formatting (e.g., with multiple lines and indentation) JSON documents. Why are you using that here?
The result of item.split('reindex-')
is a two-element list, ["", "abc-def-ghi--2020-08-30"]
. If you just want the second element, you can write:
dest:
index: "{{ item.split('reindex').1 }}"
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论