格式化 set_fact 变量 [英] Formatting set_fact variable
本文介绍了格式化 set_fact 变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要将所有用户 ID 放在一个变量中,所有用户 ID 都用 \n 分隔.代码如下.
I need to have all the userid in a single variable, all separated by \n. Code is as below.
- name: Retrieve the user id and instance
shell: ls -l {{item}} | grep -v total| awk '{print $3}'
register: find_result_userid
with_items:
- /tmp/log/logs/log1
- /tmp/log/logs/log2
- /tmp/log/logs/log3
- name: Combine all userid
set_fact:
server_names: "{{ find_result_userid.results | map(attribute='stdout_lines')|list }}"
输出如下.
ok: [localhost] => {
"ansible_facts": {
"server_names": [
[
"root",
"root",
"root"
],
[
"root",
"root",
"root"
],
[
"root",
"root",
"root"
]
]
},
"changed": false
}
我需要类似以下内容:即在单个变量中由一行分隔的所有 ID.
I need something like below: i.e all ids separated by a line in a single variable.
"server_names": [
[
"root",
"root",
"root",
"root",
"root",
"root",
"root",
"root",
"root"
]
请多多指教.
推荐答案
扁平化 列表
- set_fact:
server_names: "{{ server_names|flatten }}"
这篇关于格式化 set_fact 变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文