首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >来自ansible模块hcloud_server的循环输出

来自ansible模块hcloud_server的循环输出
EN

Stack Overflow用户
提问于 2022-04-12 07:11:39
回答 1查看 41关注 0票数 1

这是创建虚拟服务器任务的循环输出。巴斯泰宾循环

我有一些调试任务来将IP和密码从所有数据中分离出来。

代码语言:javascript
复制
- 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发送电子邮件任务:

代码语言:javascript
复制
  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 }}" 
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-04-12 08:49:14

使用set事实代替注册调试:

代码语言:javascript
复制
  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

代码语言:javascript
复制
body: "{{ access_password.msg }}" 
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71838489

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档