昨天开始学习ansible,所以我相信我可能会在这里冒着XY问题的风险,但仍然\xe2\x80\xa6
\n\n主要的yml:
\n\n- hosts: localhost\n\n vars_files:\n [ "users.yml" ]\n tasks:\n - name: manage instances\n #include_tasks: create_instance.yml\n include_tasks: inhabit_instance.yml\n with_dict: "{{users}}"\n register: res\n - name: print\n debug: msg="{{res.results}}"\nRun Code Online (Sandbox Code Playgroud)\n\ninhabit_instance.yml:
\n\n- name: Get instance info for {{ item.key }}\n ec2_instance_facts:\n profile: henryaws\n filters:\n "tag:name": "{{item.key}}"\n instance-state-name: running\n register: ec2\n- name: print\n debug:\n msg: "IP: {{ec2.instances.0.public_ip_address}}"\nRun Code Online (Sandbox Code Playgroud)\n\n这就是我想要的顶层 IP。还没有立即找到有关包含块的返回值的任何信息\xe2\x80\xa6
\n好吧,我找到了一些适合我的方法,也许它甚至是规范的?
主要.yml:
- 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
Run Code Online (Sandbox Code Playgroud)
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 }) }}"
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3558 次 |
| 最近记录: |