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.

On 16 November 2017 at 09:33, Byym Reddy <[email protected]> wrote:
> 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"}
>
> --
> You received this message because you are subscribed to the Google Groups
> "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/9d5070ae-07b2-4e94-ad5a-08db2b9b4058%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CAK5eLPRX_qKg9WcaNcUswnGoePmmUYvBNdE4Ry2ObrSsOVKn1g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to