dictionary - Formatting set_fact variable
问题描述
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 }}"
The output is as below.
ok: [localhost] => {
"ansible_facts": {
"server_names": [
[
"root",
"root",
"root"
],
[
"root",
"root",
"root"
],
[
"root",
"root",
"root"
]
]
},
"changed": false
}
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"
]
Kindly advise.
解决方案
展平列表
- set_fact:
server_names: "{{ server_names|flatten }}"
推荐阅读
- python - 如何将包含 UTF-8 数据的纯字符串转换为
- c++ - 返回的地址始终为 0 而不是实际值
- sql - 如何根据另一列计算以下n行的平均值 - SQL(Oracle)
- html - 没有标签勾号的 HTML 复选框不显示
- scenekit - 根据顶点世界位置Y坐标修改Metal片段着色
- android - 图片不会从网络加载
- python - Django:根据“a”标签点击显示不同的列表
- mysql - 通过第二个表加入条件查询
- java - 动态加载 JTable 后,在选定的 JComboBox 出现之前
- graphql - graphql - 类型错误:graphql_1.getIntrospectionQuery 不是函数