---
- hosts: localhost
gather_facts: False
roles:
- provision_ec2
# this uses a variable defined in the first role of this playbook, provision_ec2.
- hosts: "{{ hostvars['localhost'].bastion_server_group }}"
become: yes
become_method: sudo
roles:
- hosts_file
# this won't work on bastion servers until we automate a way to connect to the newly provisioned bastion server.
# This would require some proxy command and attaching an elastic IP, then pushing that to the ssh_config.
因为现在我们每次旋转新的堡垒服务器时手动执行上述注释,我需要您的帮助才能知道如何自动化将弹性IP附加到新配置的堡垒服务器的过程?我是Yaml和ansible的新手,我从最近几周开始学习yaml。
- hosts: '{{HOST_GROUP}}'
gather_facts: False
roles:
- { role: ec2_tags, when: server_type != 'bastion' }
- { role: ec2_tag_volumes, when: server_type == 'app' or server_type == 'util' }
答案 0 :(得分:0)
有ec2_eip个模块。在使用ec2
模块创建实例后立即使用它。
使用示例:
- ec2_eip:
region: "{{ region }}"
state: present
in_vpc: yes
device_id: "{{ ec2_result.instances[0].id }}"
reuse_existing_ip_allowed: yes