-
Notifications
You must be signed in to change notification settings - Fork 341
/
ec2_instance.py
2881 lines (2682 loc) · 116 KB
/
ec2_instance.py
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/python
# -*- coding: utf-8 -*-
# Copyright: Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
DOCUMENTATION = r"""
---
module: ec2_instance
version_added: 1.0.0
short_description: Create & manage EC2 instances
description:
- Create and manage AWS EC2 instances.
- This module does not support creating
L(EC2 Spot instances,https://aws.amazon.com/ec2/spot/).
- The M(amazon.aws.ec2_spot_instance) module can create and manage spot instances.
author:
- Ryan Scott Brown (@ryansb)
options:
instance_ids:
description:
- If you specify one or more instance IDs, only instances that have the specified IDs are returned.
- Mutually exclusive with O(exact_count).
type: list
elements: str
default: []
state:
description:
- Goal state for the instances.
- "O(state=present): ensures instances exist, but does not guarantee any state (e.g. running). Newly-launched instances will be run by EC2."
- "O(state=running): O(state=present) + ensures the instances are running."
- "O(state=started): O(state=running) + waits for EC2 status checks to report OK if O(wait=true)."
- "O(state=stopped): ensures an existing instance is stopped."
- "O(state=rebooted): convenience alias for O(state=stopped) immediately followed by O(state=running)."
- "O(state=restarted): convenience alias for O(state=stopped) immediately followed by O(state=started)."
- "O(state=terminated): ensures an existing instance is terminated."
- "O(state=absent): alias for O(state=terminated)."
choices: [present, terminated, running, started, stopped, restarted, rebooted, absent]
default: present
type: str
wait:
description:
- Whether or not to wait for the desired O(state) (use O(wait_timeout) to customize this).
default: true
type: bool
wait_timeout:
description:
- How long to wait (in seconds) for the instance to finish booting/terminating.
default: 600
type: int
instance_type:
description:
- Instance type to use for the instance, see
U(https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instance-types.html).
- At least one of O(instance_type) or O(launch_template) must be specificed when launching an
instance.
- When the instance is present and the O(instance_type) specified value is different from the current value,
the instance will be stopped and the instance type will be updated.
type: str
count:
description:
- Number of instances to launch.
- Setting this value will result in always launching new instances.
- Mutually exclusive with O(exact_count).
type: int
version_added: 2.2.0
exact_count:
description:
- An integer value which indicates how many instances that match the O(filters) parameter should be running.
- Instances are either created or terminated based on this value.
- If termination takes place, least recently created instances will be terminated based on Launch Time.
- Mutually exclusive with O(count), O(instance_ids).
type: int
version_added: 2.2.0
user_data:
description:
- Opaque blob of data which is made available to the EC2 instance.
type: str
aap_callback:
description:
- Preconfigured user-data to enable an instance to perform an Ansible Automation Platform
callback (Linux only).
- For Windows instances, to enable remote access via Ansible set O(aap_callback.windows) to V(true), and
optionally set an admin password.
- If using O(aap_callback.windows) and O(aap_callback.set_password), callback to Ansible Automation Platform will not
be performed but the instance will be ready to receive winrm connections from Ansible.
- Mutually exclusive with O(user_data).
type: dict
aliases: ['tower_callback']
suboptions:
windows:
description:
- Set O(aap_callback.windows=True) to use powershell instead of bash for the callback script.
type: bool
default: False
set_password:
description:
- Optional admin password to use if O(aap_callback.windows=True).
type: str
tower_address:
description:
- IP address or DNS name of Tower server. Must be accessible via this address from the
VPC that this instance will be launched in.
- Required if O(aap_callback.windows=False).
type: str
job_template_id:
description:
- Either the integer ID of the Tower Job Template, or the name.
Using a name for the job template is not supported by Ansible Tower prior to version
3.2.
- Required if O(aap_callback.windows=False).
type: str
host_config_key:
description:
- Host configuration secret key generated by the Tower job template.
- Required if O(aap_callback.windows=False).
type: str
image:
description:
- An image to use for the instance. The M(amazon.aws.ec2_ami_info) module may be used to retrieve images.
One of O(image) or O(image_id) are required when instance is not already present.
type: dict
suboptions:
id:
description:
- The AMI ID.
type: str
ramdisk:
description:
- Overrides the AMI's default ramdisk ID.
type: str
kernel:
description:
- a string AKI to override the AMI kernel.
type: str
image_id:
description:
- I(ami) ID to use for the instance. One of O(image) or O(image_id) are required when instance is not already present.
- This is an alias for O(image.id).
type: str
security_groups:
description:
- A list of security group IDs or names (strings).
- Mutually exclusive with O(security_group).
- Mutually exclusive with O(network_interfaces_ids).
type: list
elements: str
default: []
security_group:
description:
- A security group ID or name.
- Mutually exclusive with O(security_groups).
- Mutually exclusive with O(network_interfaces_ids).
type: str
name:
description:
- The Name tag for the instance.
type: str
vpc_subnet_id:
description:
- The subnet ID in which to launch the instance (VPC).
- If none is provided, M(amazon.aws.ec2_instance) will chose the default zone of the default VPC.
aliases: ['subnet_id']
type: str
network:
description:
- Either a dictionary containing the key C(interfaces) corresponding to a list of network interface IDs or
containing specifications for a single network interface.
- Use the M(amazon.aws.ec2_eni) module to create ENIs with special settings.
- This field is deprecated and will be removed in a release after 2026-12-01, use O(network_interfaces) or O(network_interfaces_ids) instead.
- Mutually exclusive with O(network_interfaces).
- Mutually exclusive with O(network_interfaces_ids).
type: dict
suboptions:
interfaces:
description:
- A list of ENI IDs (strings) or a list of objects containing the key id.
type: list
elements: str
assign_public_ip:
description:
- When C(true) assigns a public IP address to the interface.
type: bool
private_ip_address:
description:
- An IPv4 address to assign to the interface.
type: str
ipv6_addresses:
description:
- A list of IPv6 addresses to assign to the network interface.
type: list
elements: str
source_dest_check:
description:
- Controls whether source/destination checking is enabled on the interface.
- This field with be ignored when O(source_dest_check) is provided.
type: bool
description:
description:
- A description for the network interface.
type: str
private_ip_addresses:
description:
- A list of IPv4 addresses to assign to the network interface.
type: list
elements: str
subnet_id:
description:
- The subnet to connect the network interface to.
type: str
delete_on_termination:
description:
- Delete the interface when the instance it is attached to is
terminated.
type: bool
device_index:
description:
- The index of the interface to modify.
type: int
groups:
description:
- A list of security group IDs to attach to the interface.
type: list
elements: str
source_dest_check:
description:
- Controls whether source/destination checking is enabled on the interface.
type: bool
version_added: 8.2.0
network_interfaces:
description:
- A list of dictionaries containing specifications for network interfaces.
- Use the M(amazon.aws.ec2_eni) module to create ENIs with special settings.
- Mutually exclusive with O(network).
type: list
elements: dict
version_added: 8.2.0
suboptions:
assign_public_ip:
description:
- When V(true) assigns a public IP address to the interface.
type: bool
private_ip_address:
description:
- An IPv4 address to assign to the interface.
type: str
ipv6_addresses:
description:
- A list of IPv6 addresses to assign to the network interface.
type: list
elements: str
description:
description:
- A description for the network interface.
type: str
subnet_id:
description:
- The subnet to connect the network interface to.
type: str
delete_on_termination:
description:
- Delete the interface when the instance it is attached to is terminated.
type: bool
default: True
device_index:
description:
- The position of the network interface in the attachment order.
- Use device index V(0) for a primary network interface.
type: int
default: 0
groups:
description:
- A list of security group IDs or names to attach to the interface.
type: list
elements: str
private_ip_addresses:
description:
- A list of private IPv4 addresses to assign to the network interface.
- Only one private IPv4 address can be designated as primary.
- You cannot specify this option if you're launching more than one instance.
type: list
elements: dict
suboptions:
private_ip_address:
description:
- The private IPv4 address.
type: str
required: true
primary:
description:
- Indicates whether the private IPv4 address is the primary private IPv4 address.
- Only one IPv4 address can be designated as primary.
type: bool
network_interfaces_ids:
description:
- A list of ENI ids to attach to the instance.
- Mutually exclusive with O(network).
- Mutually exclusive with O(security_group).
- Mutually exclusive with O(security_groups).
type: list
elements: dict
version_added: 8.2.0
suboptions:
id:
description:
- The ID of the network interface.
type: str
required: True
device_index:
description:
- The position of the network interface in the attachment order.
type: int
default: 0
volumes:
description:
- A list of block device mappings, by default this will always use the AMI root device so the volumes option is primarily for adding more storage.
- A mapping contains the (optional) keys V(device_name), V(virtual_name), V(ebs.volume_type), V(ebs.volume_size), V(ebs.kms_key_id),
V(ebs.snapshot_id), V(ebs.iops), and V(ebs.delete_on_termination).
- For more information about each parameter, see U(https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_BlockDeviceMapping.html).
type: list
elements: dict
launch_template:
description:
- The EC2 launch template to base instance configuration on.
- At least one of O(instance_type) or O(launch_template) must be specificed when launching an
instance.
type: dict
suboptions:
id:
description:
- The ID of the launch template (optional if name is specified).
type: str
name:
description:
- The pretty name of the launch template (optional if id is specified).
type: str
version:
description:
- The specific version of the launch template to use. If unspecified, the template default is chosen.
key_name:
description:
- Name of the SSH access key to assign to the instance - must exist in the region the instance is created.
- Use M(amazon.aws.ec2_key) to manage SSH keys.
type: str
availability_zone:
description:
- Specify an availability zone to use the default subnet it. Useful if not specifying the O(vpc_subnet_id) parameter.
- If no subnet, ENI, or availability zone is provided, the default subnet in the default VPC will be used in the first AZ (alphabetically sorted).
type: str
instance_initiated_shutdown_behavior:
description:
- Whether to stop or terminate an instance upon shutdown.
choices: ['stop', 'terminate']
type: str
tenancy:
description:
- What type of tenancy to allow an instance to use. Default is V(shared) tenancy. Dedicated tenancy will incur additional charges.
- This field is deprecated and will be removed in a release after 2025-12-01, use O(placement) instead.
choices: ['dedicated', 'default']
type: str
termination_protection:
description:
- Whether to enable termination protection.
- This module will not terminate an instance with termination protection active, it must be turned off first.
type: bool
hibernation_options:
description:
- Indicates whether an instance is enabled for hibernation.
Refer U(https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/hibernating-prerequisites.html)
for Hibernation prerequisits.
type: bool
default: False
version_added: 5.0.0
cpu_credit_specification:
description:
- For T series instances, choose whether to allow increased charges to buy CPU credits if the default pool is depleted.
- Choose V(unlimited) to enable buying additional CPU credits.
choices: ['unlimited', 'standard']
type: str
cpu_options:
description:
- Reduce the number of vCPU exposed to the instance.
- Those parameters can only be set at instance launch. The two suboptions O(cpu_options.threads_per_core) and O(cpu_options.core_count) are mandatory.
- See U(https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instance-optimize-cpu.html) for combinations available.
type: dict
suboptions:
threads_per_core:
description:
- Select the number of threads per core to enable. Disable or Enable Intel HT.
choices: [1, 2]
required: true
type: int
core_count:
description:
- Set the number of core to enable.
required: true
type: int
detailed_monitoring:
description:
- Whether to allow detailed CloudWatch metrics to be collected, enabling more detailed alerting.
type: bool
ebs_optimized:
description:
- Whether instance is should use optimized EBS volumes, see U(https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/EBSOptimized.html).
type: bool
filters:
description:
- A dict of filters to apply when deciding whether existing instances match and should be altered. Each dict item
consists of a filter key and a filter value. See
U(https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_DescribeInstances.html).
for possible filters. Filter names and values are case sensitive.
- By default, instances are filtered for counting by their "Name" tag, base AMI, state (running, by default), and
subnet ID. Any queryable filter can be used. Good candidates are specific tags, SSH keys, or security groups.
type: dict
iam_instance_profile:
description:
- The ARN or name of an EC2-enabled IAM instance profile to be used.
- If a name is not provided in ARN format then the ListInstanceProfiles permission must also be granted.
U(https://docs.aws.amazon.com/IAM/latest/APIReference/API_ListInstanceProfiles.html)
- If no full ARN is provided, the role with a matching name will be used from the active AWS account.
type: str
aliases: ['instance_role']
placement_group:
description:
- The placement group that needs to be assigned to the instance.
- This field is deprecated and will be removed in a release after 2025-12-01, use O(placement) instead.
type: str
placement:
description:
- The location where the instance launched, if applicable.
type: dict
version_added: 7.0.0
suboptions:
affinity:
description: The affinity setting for the instance on the Dedicated Host.
type: str
required: false
availability_zone:
description: The Availability Zone of the instance.
type: str
required: false
group_name:
description: The name of the placement group the instance is in.
type: str
required: false
host_id:
description: The ID of the Dedicated Host on which the instance resides.
type: str
required: false
host_resource_group_arn:
description: The ARN of the host resource group in which to launch the instances.
type: str
required: false
partition_number:
description: The number of the partition the instance is in.
type: int
required: false
tenancy:
description:
- Type of tenancy to allow an instance to use. Default is shared tenancy. Dedicated tenancy will incur additional charges.
- Support for O(tenancy=host) was added in amazon.aws 7.6.0.
type: str
required: false
choices: ['dedicated', 'default', 'host']
license_specifications:
description:
- The license specifications to be used for the instance.
type: list
elements: dict
suboptions:
license_configuration_arn:
description: The Amazon Resource Name (ARN) of the license configuration.
type: str
required: true
additional_info:
description:
- Reserved for Amazon's internal use.
type: str
version_added: 7.1.0
metadata_options:
description:
- Modify the metadata options for the instance.
- See U(https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-instance-metadata.html) for more information.
- The two suboptions O(metadata_options.http_endpoint) and O(metadata_options.http_tokens) are supported.
type: dict
version_added: 2.0.0
suboptions:
http_endpoint:
description:
- Enables or disables the HTTP metadata endpoint on instances.
- If specified a value of disabled, metadata of the instance will not be accessible.
choices: [enabled, disabled]
default: enabled
type: str
http_tokens:
description:
- Set the state of token usage for instance metadata requests.
- If the state is optional (v1 and v2), instance metadata can be retrieved with or without a signed token header on request.
- If the state is required (v2), a signed token header must be sent with any instance metadata retrieval requests.
choices: [optional, required]
default: optional
type: str
http_put_response_hop_limit:
version_added: 4.0.0
type: int
description:
- The desired HTTP PUT response hop limit for instance metadata requests.
- The larger the number, the further instance metadata requests can travel.
default: 1
http_protocol_ipv6:
version_added: 4.0.0
type: str
description:
- Whether the instance metadata endpoint is available via IPv6 (V(enabled)) or not (V(disabled)).
choices: [enabled, disabled]
default: 'disabled'
instance_metadata_tags:
version_added: 4.0.0
type: str
description:
- Whether the instance tags are availble (V(enabled)) via metadata endpoint or not (V(disabled)).
choices: [enabled, disabled]
default: 'disabled'
extends_documentation_fragment:
- amazon.aws.common.modules
- amazon.aws.region.modules
- amazon.aws.tags
- amazon.aws.boto3
"""
EXAMPLES = r"""
# Note: These examples do not set authentication details, see the AWS Guide for details.
- name: Terminate every running instance in a region. Use with EXTREME caution.
amazon.aws.ec2_instance:
state: absent
filters:
instance-state-name: running
- name: restart a particular instance by its ID
amazon.aws.ec2_instance:
state: restarted
instance_ids:
- i-12345678
- name: start an instance with a public IP address
amazon.aws.ec2_instance:
name: "public-compute-instance"
key_name: "prod-ssh-key"
vpc_subnet_id: subnet-5ca1ab1e
instance_type: c5.large
security_group: default
network_interfaces:
- assign_public_ip: true
image_id: ami-123456
tags:
Environment: Testing
- name: start an instance and Add EBS
amazon.aws.ec2_instance:
name: "public-withebs-instance"
vpc_subnet_id: subnet-5ca1ab1e
instance_type: t2.micro
key_name: "prod-ssh-key"
security_group: default
volumes:
- device_name: /dev/sda1
ebs:
volume_size: 16
delete_on_termination: true
- name: start an instance and Add EBS volume from a snapshot
amazon.aws.ec2_instance:
name: "public-withebs-instance"
instance_type: t2.micro
image_id: ami-1234567890
vpc_subnet_id: subnet-5ca1ab1e
volumes:
- device_name: /dev/sda2
ebs:
snapshot_id: snap-1234567890
- name: Create EC2 instance with termination protection turned on
amazon.aws.ec2_instance:
name: "my-ec2-instance"
vpc_subnet_id: subnet-5ca1ab1e
instance_type: t3.small
image_id: ami-123456
termination_protection: true
wait: true
- name: start an instance with a cpu_options
amazon.aws.ec2_instance:
name: "public-cpuoption-instance"
vpc_subnet_id: subnet-5ca1ab1e
tags:
Environment: Testing
instance_type: c4.large
volumes:
- device_name: /dev/sda1
ebs:
delete_on_termination: true
cpu_options:
core_count: 1
threads_per_core: 1
- name: start an instance and have it begin a Tower callback on boot
amazon.aws.ec2_instance:
name: "tower-callback-test"
key_name: "prod-ssh-key"
vpc_subnet_id: subnet-5ca1ab1e
security_group: default
tower_callback:
# IP or hostname of tower server
tower_address: 1.2.3.4
job_template_id: 876
host_config_key: '[secret config key goes here]'
network_interfaces:
- assign_public_ip: true
image_id: ami-123456
cpu_credit_specification: unlimited
tags:
SomeThing: "A value"
- name: start an instance with ENI (An existing ENI ID is required)
amazon.aws.ec2_instance:
name: "public-eni-instance"
key_name: "prod-ssh-key"
vpc_subnet_id: subnet-5ca1ab1e
network_interfaces_ids:
- id: "eni-12345"
device_index: 0
tags:
Env: "eni_on"
volumes:
- device_name: /dev/sda1
ebs:
delete_on_termination: true
instance_type: t2.micro
image_id: ami-123456
- name: add second ENI interface
amazon.aws.ec2_instance:
name: "public-eni-instance"
network_interfaces_ids:
- id: "eni-12345"
device_index: 0
- id: "eni-67890"
device_index: 1
image_id: ami-123456
tags:
Env: "eni_on"
instance_type: t2.micro
- name: start an instance with metadata options
amazon.aws.ec2_instance:
name: "public-metadataoptions-instance"
vpc_subnet_id: subnet-5calable
instance_type: t3.small
image_id: ami-123456
tags:
Environment: Testing
metadata_options:
http_endpoint: enabled
http_tokens: optional
# ensure number of instances running with a tag matches exact_count
- name: start multiple instances
amazon.aws.ec2_instance:
instance_type: t3.small
image_id: ami-123456
exact_count: 5
region: us-east-2
vpc_subnet_id: subnet-0123456
network_interfaces:
- assign_public_ip: true
groups:
- default
tags:
foo: bar
# launches multiple instances - specific number of instances
- name: start specific number of multiple instances
amazon.aws.ec2_instance:
instance_type: t3.small
image_id: ami-123456
count: 3
region: us-east-2
network_interfaces:
- assign_public_ip: true
groups:
- default
subnet_id: subnet-0123456
state: present
tags:
foo: bar
# launches an instance with a primary and a secondary network interfaces
- name: start an instance with a primary and secondary network interfaces
amazon.aws.ec2_instance:
instance_type: t2.large
image_id: ami-123456
region: us-east-2
network_interfaces:
- assign_public_ip: true
groups:
- default
subnet_id: subnet-0123456
private_ip_addresses:
- primary: true
private_ip_address: 168.50.4.239
- primary: false
private_ip_address: 168.50.4.237
state: present
tags:
foo: bar
# launches a mac instance with HostResourceGroupArn and LicenseSpecifications
- name: start a mac instance with a host resource group and license specifications
amazon.aws.ec2_instance:
name: "mac-compute-instance"
key_name: "prod-ssh-key"
vpc_subnet_id: subnet-5ca1ab1e
instance_type: mac1.metal
security_group: default
placement:
host_resource_group_arn: arn:aws:resource-groups:us-east-1:123456789012:group/MyResourceGroup
license_specifications:
- license_configuration_arn: arn:aws:license-manager:us-east-1:123456789012:license-configuration:lic-0123456789
image_id: ami-123456
tags:
Environment: Testing
"""
RETURN = r"""
instance_ids:
description: A list of EC2 instance IDs matching the provided specification and filters.
returned: always
type: list
sample: ["i-0123456789abcdef0", "i-0123456789abcdef1"]
version_added: 5.3.0
changed_ids:
description: A list of the set of EC2 instance IDs changed by the module action.
returned: when instances that must be present are launched
type: list
sample: ["i-0123456789abcdef0"]
version_added: 5.3.0
terminated_ids:
description: A list of the set of EC2 instance IDs terminated by the module action.
returned: when instances that must be absent are terminated
type: list
sample: ["i-0123456789abcdef1"]
version_added: 5.3.0
instances:
description: A list of EC2 instances.
returned: when O(wait=true) or when matching instances already exist
type: complex
contains:
ami_launch_index:
description: The AMI launch index, which can be used to find this instance in the launch group.
returned: always
type: int
sample: 0
architecture:
description: The architecture of the image.
returned: always
type: str
sample: x86_64
block_device_mappings:
description: Any block device mapping entries for the instance.
returned: always
type: complex
contains:
device_name:
description: The device name exposed to the instance (for example, /dev/sdh or xvdh).
returned: always
type: str
sample: /dev/sdh
ebs:
description: Parameters used to automatically set up EBS volumes when the instance is launched.
returned: always
type: complex
contains:
attach_time:
description: The time stamp when the attachment initiated.
returned: always
type: str
sample: "2017-03-23T22:51:24+00:00"
delete_on_termination:
description: Indicates whether the volume is deleted on instance termination.
returned: always
type: bool
sample: true
status:
description: The attachment state.
returned: always
type: str
sample: attached
volume_id:
description: The ID of the EBS volume.
returned: always
type: str
sample: vol-12345678
capacity_reservation_specification:
description: Information about the Capacity Reservation targeting option.
type: complex
contains:
capacity_reservation_preference:
description: Describes the Capacity Reservation preferences.
type: str
sample: open
client_token:
description: The idempotency token you provided when you launched the instance, if applicable.
returned: always
type: str
sample: mytoken
cpu_options:
description: The CPU options for the instance.
type: complex
contains:
core_count:
description: The number of CPU cores for the instance.
type: int
sample: 1
threads_per_core:
description: The number of threads per CPU core.
type: int
sample: 2
amd_sev_snp:
description: Indicates whether the instance is enabled for AMD SEV-SNP.
type: str
sample: enabled
current_instance_boot_mode:
description: The boot mode that is used to boot the instance at launch or start.
type: str
sample: legacy-bios
ebs_optimized:
description: Indicates whether the instance is optimized for EBS I/O.
returned: always
type: bool
sample: false
ena_support:
description: Specifies whether enhanced networking with ENA is enabled.
returned: always
type: bool
sample: true
enclave_options:
description: Indicates whether the instance is enabled for Amazon Web Services Nitro Enclaves.
type: dict
contains:
enabled:
description: If this parameter is set to true, the instance is enabled for Amazon Web Services Nitro Enclaves.
returned: always
type: bool
sample: false
hibernation_options:
description: Indicates whether the instance is enabled for hibernation.
type: dict
contains:
configured:
description: If true, your instance is enabled for hibernation; otherwise, it is not enabled for hibernation.
returned: always
type: bool
sample: false
hypervisor:
description: The hypervisor type of the instance.
returned: always
type: str
sample: xen
iam_instance_profile:
description: The IAM instance profile associated with the instance, if applicable.
returned: always
type: complex
contains:
arn:
description: The Amazon Resource Name (ARN) of the instance profile.
returned: always
type: str
sample: "arn:aws:iam::123456789012:instance-profile/myprofile"
id:
description: The ID of the instance profile.
returned: always
type: str
sample: JFJ397FDG400FG9FD1N
image_id:
description: The ID of the AMI used to launch the instance.
returned: always
type: str
sample: ami-0011223344
instance_id:
description: The ID of the instance.
returned: always
type: str
sample: i-012345678
instance_type:
description: The instance type size of the running instance.
returned: always
type: str
sample: t2.micro
key_name:
description: The name of the key pair, if this instance was launched with an associated key pair.
returned: always
type: str
sample: my-key
launch_time:
description: The time the instance was launched.
returned: always
type: str
sample: "2017-03-23T22:51:24+00:00"
licenses:
description: The license configurations for the instance.
returned: When license specifications are provided.
type: list
elements: dict
contains:
license_configuration_arn:
description: The Amazon Resource Name (ARN) of the license configuration.
returned: always
type: str
sample: arn:aws:license-manager:us-east-1:123456789012:license-configuration:lic-0123456789
metadata_options:
description: The metadata options for the instance.
returned: always
type: complex
contains:
http_endpoint:
description: Indicates whether the HTTP metadata endpoint on your instances is enabled or disabled.
type: str
sample: enabled
http_protocol_ipv6:
description: Indicates whether the IPv6 endpoint for the instance metadata service is enabled or disabled.
type: str
sample: disabled
http_put_response_hop_limit:
description: The maximum number of hops that the metadata token can travel.
type: int
sample: 1
http_tokens:
description: Indicates whether IMDSv2 is required.
type: str
sample: optional
instance_metadata_tags:
description: Indicates whether access to instance tags from the instance metadata is enabled or disabled.
type: str
sample: disabled
state:
description: The state of the metadata option changes.
type: str
sample: applied
monitoring:
description: The monitoring for the instance.
returned: always
type: complex
contains:
state:
description: Indicates whether detailed monitoring is enabled. Otherwise, basic monitoring is enabled.
returned: always
type: str
sample: disabled
network_interfaces:
description: One or more network interfaces for the instance.
returned: always
type: list
elements: dict
contains:
association:
description: The association information for an Elastic IPv4 associated with the network interface.
returned: always
type: complex
contains:
ip_owner_id:
description: The ID of the owner of the Elastic IP address.
returned: always
type: str
sample: amazon
public_dns_name:
description: The public DNS name.
returned: always
type: str
sample: ""
public_ip:
description: The public IP address or Elastic IP address bound to the network interface.
returned: always
type: str
sample: 1.2.3.4
attachment:
description: The network interface attachment.
returned: always
type: complex
contains:
attach_time:
description: The time stamp when the attachment initiated.
returned: always
type: str
sample: "2017-03-23T22:51:24+00:00"
attachment_id:
description: The ID of the network interface attachment.
returned: always
type: str