【发布时间】:2017-11-30 00:02:01
【问题描述】:
- hosts: ALL
gather_facts: true
remote_user:test
vars:
Env: "{{ env }}"
tasks:
- ec2_remote_facts:
region: us-east-1
aws_access_key: "{{ aws_access_key }}"
aws_secret_key: "{{ aws_secret_key }}"
filters:
"tag:Env": "{{ env }}"
register: instance_facts
- name: group_hosts
add_host: hostname={{ item }} groups=dev
with_items: "{{ instance_facts.instances|map(attribute="private_ip_address)|list }}"
- name: "loop over hosts for hostnames"
hostname:
name: {{ item }}
with_items: "{{ instance_facts.instances|map(attribute=' ')|list }}"
我在本手册中的目的是获取 tag_Name 并在实例中设置为与主机名相同。我正在尝试不同的事情,但是在“为主机循环主机”任务中使用标签属性时卡住了。我如何提及 Tag = "Name" 以将其保存为主机名,因为它是一个嵌套属性?
【问题讨论】:
标签: amazon-ec2 ansible jinja2