下面是我的样例yaml文件
student:
faculty: "Information Technology"
code: "FC1412"
abraham:
country: "UK"
age: "56"
aaron:
country: "UK"
age: "56"
chin:
country: "UK"
age: "56"下面是我的Ansible代码
- slurp:
src: {{ yaml_file_directory }}
register: registerValue
- debug:
msg: {{ registerValue['content'] | b64decode | from_yaml }}它将给出如下输出
student: {
faculty: "Information Technology",
code: "FC1412",
abraham: {
country: "UK",
age: "56"
},
aaron:
country: "UK",
age: "56",
},
jamess: {
country: "UK",
age: "56"
}
}是否有可能替换像aaron这样的值,从56岁到57岁。我希望你们能给我一些建议
发布于 2021-08-02 06:15:01
字典在Ansible中是不可变的。你必须改写整个字典。例如,将更新放入字典中
update:
aaron:
age: "57"并使用filter combine。设置recusive=True以保留所有属性
- set_fact:
student: "{{ student|combine(update, recursive=True) }}"
vars:
update:
aaron:
age: "57"给出
student:
aaron:
age: '57'
country: UK
abraham:
age: '56'
country: UK
code: FC1412
faculty: Information Technology
jamess:
age: '56'
country: UKhttps://stackoverflow.com/questions/68615947
复制相似问题