# Set AWS Hostname

**URL:** <https://forum.ansible.com/t/set-aws-hostname/26042>\
**Category:** Ansible Project\
**Tags:** aws\
**Created:** [November 16, 2017, 9:33am UTC](https://forum.ansible.com/t/set-aws-hostname/26042 "2017-11-16T09:33:02Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Byym\_Reddy](https://avatars.discourse-cdn.com/v4/letter/b/e274bd/32.png) [@Byym\_Reddy](https://forum.ansible.com/u/Byym_Reddy)\
**Post date:** [November 16, 2017, 9:33am UTC](https://forum.ansible.com/t/set-aws-hostname/26042/1 "2017-11-16T09:33:02Z")

</div>

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.

```auto
---
- 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 

```

```auto
Supported parameters include: assign_public_ip, aws_access_key, aws_secret_key, count, count_tag, ebs_optimized, 

```

```auto
ec2_url, exact_count, group, group_id, id, image, instance_ids, instance_initiated_shutdown_behavior, 

```

```auto
instance_profile_name, instance_tags, instance_type, kernel, key_name, monitoring, network_interfaces, 

```

```auto
placement_group, private_ip, profile, ramdisk, region, security_token, source_dest_check, spot_launch_group, 

```

```auto
spot_price, spot_type, spot_wait_timeout, state, tenancy, termination_protection, user_data, validate_certs, 

```

```auto
volumes, vpc_subnet_id, wait, wait_timeout, zone"}

```

---

<div class="post-metadata">

**Author:** ![Dick\_Davies](https://avatars.discourse-cdn.com/v4/letter/d/b9e5f3/32.png) [@Dick\_Davies](https://forum.ansible.com/u/Dick_Davies)\
**Post date:** [November 16, 2017, 10:49am UTC](https://forum.ansible.com/t/set-aws-hostname/26042/2 "2017-11-16T10:49:09Z")

</div>

You have a YAML nesting mistake - Ansible is reading your register: as  
a property of the task,  
rather than at the same level as the task.  
Your 'with\_items:' on the next task has the same issue.
