-
Notifications
You must be signed in to change notification settings - Fork 0
/
create-ec2-2-IOS.yml
80 lines (70 loc) · 2.33 KB
/
create-ec2-2-IOS.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# Play 1: Create the routers
- name: Create EC2 instance(s)
hosts: localhost
connection: local
become: false
gather_facts: true
vars_files:
- ./vars/sw_version.yml
- ./vars/aws_common.yml
vars:
- ec2_instance_type: c4.large
- ec2_ami_id: "{{ map['CSR_16_12'] }}"
- ec2_name_tag: nleiva-cisco-ios
- ec2_ansible_group_tag: Routers
- ec2_username: ec2-user
# roles:
# - { role: install_dependencies, become: true }
tasks:
- name: Loop to create N=2 instances
ansible.builtin.include_tasks: create-ec2-2-IOS-tasks.yml
loop:
- 1
- 2
loop_control:
loop_var: router_number
- name: Grab all network interfaces for VPC (NETWORKING MODE)
amazon.aws.ec2_eni_info:
region: "{{ ec2_region }}"
filters:
vpc-id: "{{ create_vpc.vpc.id }}"
register: eni_facts
- name: Disable Source/Dest check on instances (NETWORKING MODE)
amazon.aws.ec2_eni:
eni_id: "{{ item['network_interface_id'] }}"
region: "{{ ec2_region }}"
source_dest_check: false
with_items:
- "{{ eni_facts['network_interfaces'] }}"
# Play 2: Configure routers we just created
- name: Configure Router(s)
hosts: "my_routers"
connection: network_cli
become: true
# strategy: free
become_method: enable
gather_facts: true
tasks:
- name: Display variables/facts for each router
ansible.builtin.debug:
msg: "Running {{ ansible_net_model }} {{ ansible_net_version }}, IP address: {{ ansible_host }}"
- name: Configure routers
ansible.builtin.include_role:
name: configure_routers
- name: Routers access details
ansible.builtin.debug:
msg: "{{ short_name }} -> {{ access }}"
- name: Print out SSH access details
ansible.builtin.debug:
msg: "{{ hostvars[inventory_hostname]['instance_ssh'] }}"
when: hostvars[inventory_hostname]['instance_ssh'] is defined
- name: Send report e-mail using SendGrid
community.general.sendgrid:
api_key: "{{ sendgrid_api_key }}"
from_address: "{{ sendgrid_from_address }}"
to_addresses: "{{ sendgrid_to_address }}"
subject: "{{ sendgrid_email_subject }}"
body: "{{ lookup('template', 'report.j2') }}"
html_body: true
delegate_to: localhost
run_once: true