![](/img/trans.png)
[英]How do I reset value for a variable passed from loop without set_fact ANSIBLE?
[英]Ansible loop through ec2_instance_facts results - diff output debug vs set_fact
我在debug和set_fact中使用相同的方法得到不同的输出。
- name: Get EC2 instances
ec2_instance_facts:
filters:
"tag:Name": "{{ item }}"
loop:
- value
- value
register: servers
- debug:
msg: "{{ item.instances | map(attribute='private_ip_address') | list }}"
loop: "{{ servers.results }}"
- name: Set the private IPs list
set_fact:
private_ips: "{{ item.instances | map(attribute='private_ip_address') | list }}"
loop: "{{ servers.results }}"
- debug:
var: private_ips
在最初的ec2_instance_facts循环中,输出6个实例。 在调试循环期间获取私有IP,所有6个IP都输出,虽然在2个单独的块中(我猜测从初始循环 - 2在第一个块中输出,然后是剩余的4个)。
但是,当使用set_fact时,我只获得前2个IP。 我猜我正在使它变得比它需要的更难,并且必须正确地使用第一个循环,但是我被卡住了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.