| 1 |
#!/usr/bin/python |
| 2 |
# -*- coding: utf-8 -*- |
| 3 |
|
| 4 |
# Copyright: Ansible Project |
| 5 |
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) |
| 6 |
|
| 7 |
DOCUMENTATION = r""" |
| 8 |
--- |
| 9 |
module: ec2_import_image_info |
| 10 |
version_added: 7.0.0 |
| 11 |
short_description: Gather information about import virtual machine tasks |
| 12 |
description: |
| 13 |
- Displays details about an import virtual machine tasks that are already created. |
| 14 |
author: |
| 15 |
- Alina Buzachis (@alinabuzachis) |
| 16 |
options: |
| 17 |
import_task_ids: |
| 18 |
description: The IDs of the import image tasks. |
| 19 |
type: list |
| 20 |
elements: str |
| 21 |
aliases: ["ids"] |
| 22 |
filters: |
| 23 |
description: |
| 24 |
- A dict of filters to apply. Each dict item consists of a filter key and a filter value. |
| 25 |
- See U(https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_DescribeImportImageTasks.html) for possible filters. |
| 26 |
type: list |
| 27 |
elements: dict |
| 28 |
extends_documentation_fragment: |
| 29 |
- amazon.aws.common.modules |
| 30 |
- amazon.aws.region.modules |
| 31 |
- amazon.aws.boto3 |
| 32 |
""" |
| 33 |
|
| 34 |
EXAMPLES = r""" |
| 35 |
# Note: These examples do not set authentication details, see the AWS Guide for details. |
| 36 |
- name: Check status of import image |
| 37 |
amazon.aws.ec2_import_image_info: |
| 38 |
filters: |
| 39 |
- Name: "tag:Name" |
| 40 |
Values: ["clone-vm-import-image"] |
| 41 |
- Name: "task-state" |
| 42 |
Values: ["completed", "active"] |
| 43 |
""" |
| 44 |
|
| 45 |
RETURN = r""" |
| 46 |
import_image: |
| 47 |
description: A list of EC2 import tasks. |
| 48 |
returned: always |
| 49 |
type: complex |
| 50 |
contains: |
| 51 |
task_name: |
| 52 |
description: |
| 53 |
- The name of the EC2 image import task. |
| 54 |
type: str |
| 55 |
architecture: |
| 56 |
description: |
| 57 |
- The architecture of the virtual machine. |
| 58 |
type: str |
| 59 |
image_id: |
| 60 |
description: |
| 61 |
- The ID of the Amazon Machine Image (AMI) created by the import task. |
| 62 |
type: str |
| 63 |
import_task_id: |
| 64 |
description: |
| 65 |
- The task ID of the import image task. |
| 66 |
type: str |
| 67 |
progress: |
| 68 |
description: |
| 69 |
- The progress of the task. |
| 70 |
type: str |
| 71 |
snapshot_details: |
| 72 |
description: |
| 73 |
- Describes the snapshot created from the imported disk. |
| 74 |
type: dict |
| 75 |
contains: |
| 76 |
description: |
| 77 |
description: |
| 78 |
- A description for the snapshot. |
| 79 |
type: str |
| 80 |
device_name: |
| 81 |
description: |
| 82 |
- The block device mapping for the snapshot. |
| 83 |
type: str |
| 84 |
disk_image_size: |
| 85 |
description: |
| 86 |
- The size of the disk in the snapshot, in GiB. |
| 87 |
type: float |
| 88 |
format: |
| 89 |
description: |
| 90 |
- The format of the disk image from which the snapshot is created. |
| 91 |
type: str |
| 92 |
progress: |
| 93 |
description: |
| 94 |
- The percentage of progress for the task. |
| 95 |
type: str |
| 96 |
snapshot_id: |
| 97 |
description: |
| 98 |
- The snapshot ID of the disk being imported. |
| 99 |
type: str |
| 100 |
status: |
| 101 |
description: |
| 102 |
- A brief status of the snapshot creation. |
| 103 |
type: str |
| 104 |
status_message: |
| 105 |
description: |
| 106 |
- A detailed status message for the snapshot creation. |
| 107 |
type: str |
| 108 |
url: |
| 109 |
description: |
| 110 |
- The URL used to access the disk image. |
| 111 |
type: str |
| 112 |
user_bucket: |
| 113 |
description: |
| 114 |
- The Amazon S3 bucket for the disk image. |
| 115 |
type: dict |
| 116 |
status: |
| 117 |
description: |
| 118 |
- A brief status of the task. |
| 119 |
type: str |
| 120 |
status_message: |
| 121 |
description: |
| 122 |
- A detailed status message of the import task. |
| 123 |
type: str |
| 124 |
license_specifications: |
| 125 |
description: |
| 126 |
- The ARNs of the license configurations. |
| 127 |
type: dict |
| 128 |
usage_operation: |
| 129 |
description: |
| 130 |
- The usage operation value. |
| 131 |
type: dict |
| 132 |
description: |
| 133 |
description: |
| 134 |
- A description string for the import image task. |
| 135 |
type: str |
| 136 |
encrypted: |
| 137 |
description: |
| 138 |
- Specifies whether the destination AMI of the imported image should be encrypted. |
| 139 |
type: bool |
| 140 |
hypervisor: |
| 141 |
description: |
| 142 |
- The target hypervisor platform. |
| 143 |
type: str |
| 144 |
kms_key_id: |
| 145 |
description: |
| 146 |
- The identifier for the symmetric KMS key that was used to create the encrypted AMI. |
| 147 |
type: str |
| 148 |
license_type: |
| 149 |
description: |
| 150 |
- The license type to be used for the Amazon Machine Image (AMI) after importing. |
| 151 |
type: str |
| 152 |
platform: |
| 153 |
description: |
| 154 |
- The operating system of the virtual machine. |
| 155 |
type: str |
| 156 |
role_name: |
| 157 |
description: |
| 158 |
- The name of the role to use when not using the default role, 'vmimport'. |
| 159 |
type: str |
| 160 |
tags: |
| 161 |
description: |
| 162 |
- The tags to apply to the import image task during creation. |
| 163 |
type: dict |
| 164 |
""" |
| 165 |
|
| 166 |
from ansible_collections.amazon.aws.plugins.module_utils.ec2 import AnsibleEC2Error |
| 167 |
from ansible_collections.amazon.aws.plugins.module_utils.ec2 import describe_import_image_tasks_as_snake_dict |
| 168 |
from ansible_collections.amazon.aws.plugins.module_utils.modules import AnsibleAWSModule |
| 169 |
|
| 170 |
|
| 171 |
def main(): |
| 172 |
argument_spec = dict( |
| 173 |
import_task_ids=dict(type="list", elements="str", aliases=["ids"]), |
| 174 |
filters=dict(type="list", elements="dict"), |
| 175 |
) |
| 176 |
|
| 177 |
module = AnsibleAWSModule(argument_spec=argument_spec, supports_check_mode=True) |
| 178 |
client = module.client("ec2") |
| 179 |
params = {} |
| 180 |
|
| 181 |
if module.params.get("filters"): |
| 182 |
params["Filters"] = module.params["filters"] |
| 183 |
if module.params.get("import_task_ids"): |
| 184 |
params["ImportTaskIds"] = module.params["import_task_ids"] |
| 185 |
|
| 186 |
try: |
| 187 |
module.exit_json(import_image=describe_import_image_tasks_as_snake_dict(client, **params)) |
| 188 |
except AnsibleEC2Error as e: |
| 189 |
module.fail_json_aws_error(e) |
| 190 |
|
| 191 |
|
| 192 |
if __name__ == "__main__": |
| 193 |
main() |