这是创建虚拟服务器任务的循环输出。巴斯泰宾循环
我有一些调试任务来将IP和密码从所有数据中分离出来。
- name: Display password of new server
debug:
msg: Ip of server is - {{ results | map(attribute='hcloud_server') | map(attribute='ipv4_address') }} and password is - {{ results | map(attribute='root_password') }}
register: access_password在完成此任务后,当我将文本输出发送到Ansible {'msg': "Ip of server is - ['11.111.111.181'] and password is - ['DFDFDFDFDFDFDFDF']", 'failed': False, 'changed': False}的电子邮件时,我会得到一些文本输出。
你能帮忙吗,我怎样才能用grep和regex消除{'msg':和, 'failed': False, 'changed': False}?这可以在命令msg之后使用grep吗?
使用模块community.general.mail发送电子邮件任务:
community.general.mail:
host: smtp.gmail.com
port: 587
username: mail@gmail.com
password: pass
to:John Smith <user@mail.com>
subject: Server was created
body: Server with name {{ item.name }} has been successfully created. Properties of server - "{{ cx11 }}"
body: "{{ access_password }}" 发布于 2022-04-12 08:49:14
使用set事实代替注册调试:
tasks:
- name: Display password of new server
set_fact:
access_password: Ip of server is - {{ results | map(attribute='hcloud_server') | map(attribute='ipv4_address') }} and password is - {{ results | map(attribute='root_password') }}或者,如果要保留调试结果,请使用access_password.msg
body: "{{ access_password.msg }}" https://stackoverflow.com/questions/71838489
复制相似问题