来自ansible模块的循环输出hcloud_server
Loop output from ansible module hcloud_server
这是创建虚拟服务器任务的循环输出。
loop in pastebin
我有一些调试任务要将 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 和正则表达式消除 {'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 }}"
使用 set fact 代替 register debug:
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 }}"
这是创建虚拟服务器任务的循环输出。 loop in pastebin
我有一些调试任务要将 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 和正则表达式消除 {'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 }}"
使用 set fact 代替 register debug:
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 }}"