I’m using ansible to create aws instances. I want to set the hostname of the instance created. The scripts available around have deprecated tags. ‘register’ is no more a supported parameter with ec2. Below my sample script. In turn, add_host doesn’t work. How to set hostname with ansible script? Any help appreciated.
---
- name: Provision Instance
ec2:
aws_access_key: "{{ key1 }}"
aws_secret_key: "{{ key2 }}"
key_name: "{{ key }}"
instance_type: "t2.micro"
image: "ami-ccecf5af"
region: "ap-southeast-2"
group: "SERVERS_PROD"
state: present
#zone: 1
vpc_subnet_id: "subnet-4"
instance_tags:
Name: Sample
Env: production
Owner: Company
InstanceDescription: Sample Company
CreatedBy: John
ManagedBy: Logistics
#ebs_optimized: yes
assign_public_ip: no
wait: true
count: 1
volumes:
- device_name: /dev/sda1
device_type: gp2
volume_size: "20"
delete_on_termination: true
- device_name: /dev/sdf
device_type: gp2
volume_size: "10"
delete_on_termination: true
register:ec2
- name: Add new instance to host group
add_host:
hostname: "A01LPBSIM01"
groupname: SERVERS_PROD
with_items: "{{ ec2 }}"
fatal: [localhost]: FAILED! => {"changed": false, "msg": "Unsupported parameters for (ec2) module: register
Supported parameters include: assign_public_ip, aws_access_key, aws_secret_key, count, count_tag, ebs_optimized,
ec2_url, exact_count, group, group_id, id, image, instance_ids, instance_initiated_shutdown_behavior,
instance_profile_name, instance_tags, instance_type, kernel, key_name, monitoring, network_interfaces,
placement_group, private_ip, profile, ramdisk, region, security_token, source_dest_check, spot_launch_group,
spot_price, spot_type, spot_wait_timeout, state, tenancy, termination_protection, user_data, validate_certs,
volumes, vpc_subnet_id, wait, wait_timeout, zone"}