gpt4 book ai didi

ansible - 如何将结果从 include_tasks 传回

转载 作者:行者123 更新时间:2023-12-03 23:55:10 35 4
gpt4 key购买 nike

昨天开始学习ansible,所以我相信我可能会在这里冒XY问题的风险,但仍然......

主要的yml:

- hosts: localhost

vars_files:
[ "users.yml" ]
tasks:
- name: manage instances
#include_tasks: create_instance.yml
include_tasks: inhabit_instance.yml
with_dict: "{{users}}"
register: res
- name: print
debug: msg="{{res.results}}"

inhabit_instance.yml:
- name: Get instance info for {{ item.key }}
ec2_instance_facts:
profile: henryaws
filters:
"tag:name": "{{item.key}}"
instance-state-name: running
register: ec2
- name: print
debug:
msg: "IP: {{ec2.instances.0.public_ip_address}}"

这就是我希望拥有的顶级 IP。还没有立即找到有关 include 块的返回值的任何信息...

最佳答案

嗯,我找到了一些适合我的方法,也许它甚至是规范的?

主文件:

- hosts: localhost

vars_files:
[ "users.yml" ]
vars:
ec_results: {}
tasks:
- name: manage instances
#include_tasks: create_instance.yml
include_tasks: inhabit_instance.yml
with_dict: "{{users}}"
register: res

inhabit_instance.yml:
- name: Get instance info for {{ item.key }}
ec2_instance_facts:
profile: henryaws
filters:
"tag:name": "{{item.key}}"
instance-state-name: running
register: ec2
- name: update
set_fact:
ec_results: "{{ ec_results|combine({ item.key: ec2.instances.0.public_ip_address }) }}"

关于ansible - 如何将结果从 include_tasks 传回,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49609615/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com