Hi all,

I ran into a problem yesterday trying to set up a AWS instance via an
Ansible playbook.  I'm running Ansible 2.7.1 on Gentoo (AMD64).

I have a host variable, `volume_size`, which is the size of the volume
in GB… and in my playbook, I tried putting the following code:

> - name: Provision instances
>   ec2_instance:
>     state: present
>     security_group: "{{hostvars[item]['security_group']}}"
>     key_name: "{{aws_key_name}}"
>     region: "{{hostvars[item]['region']}}"
>     instance_type: "{{hostvars[item]['instance_type']}}"
>     image_id: "{{hostvars[item]['image_id']}}"
>     wait: true
>     wait_timeout: "{{hostvars[item]['wait_timeout']}}"
>     network:
>       assign_public_ip: true
>     tags:
>       Name: '{{item}}'
>       JiraStory: "{{hostvars[item].get('jira_story','N/A')}}"
>     volumes:
>     - device_name: /dev/sdb
>       ebs:
>         encrypted: "{{hostvars[item].get('encrypted','false') == 'true'}}"
>         volume_size: "{{hostvars[item].get('volume_size',100)}}"
>         volume_type: "{{hostvars[item].get('volume_type','gp2')}}"
>   loop: "{{ groups.aws }}"
>   when: "'aws' in groups"
>   register: ec2
>   tags:
>   - aws

That yielded this error:

> An exception occurred during task execution. To see the full traceback, use 
> -vvv. The error was: Invalid type for parameter 
> BlockDeviceMappings[0].Ebs.VolumeSize, value: 100, type: <type 'str'>, valid 
> types: <type 'int'>, <type 'long'>                                            
>                                                                               
>                  
> failed: [localhost] (item=awstest.on.widesky.cloud) => {"boto3_version": 
> "1.7.19", "botocore_version": "1.10.19", "changed": false, "item": 
> "awstest.on.widesky.cloud", "msg": "Failed to create new EC2 instance: 
> Parameter validation failed:\nInvalid type for parameter 
> BlockDeviceMappings[0].Ebs.Encrypted, value: true, type: <type 'str'>, valid 
> types: <type 'bool'>\nInvalid type for parameter 
> BlockDeviceMappings[0].Ebs.VolumeSize, value: 100, type: <type 'str'>, valid 
> types: <type 'int'>, <type 'long'>"}                                          
>             
>         to retry, use: --limit 
> @/home/stuartl/vrt/projects/widesky/ops/deploy/site.retry

I thought, maybe it's being read from the hosts file as a string and
needs to be passed through the `int` constructor.  Tried wrapping the
variable in `int()`, that failed, but then I read the jinja2 docs which
said to use `{{variable | int}}`.  No problem…

>     volumes:
>     - device_name: /dev/sdb
>       ebs:
>         encrypted: "{{hostvars[item].get('encrypted','false') == 'true'}}"
>         volume_size: "{{hostvars[item].get('volume_size',100) | int}}"
>         volume_type: "{{hostvars[item].get('volume_type','gp2')}}"

I got the same error.

I suspect that the integer is then getting cast *back* to a string
before being passed onto `boto3`, which is then barfing on it.

Is there a way to tell Ansible that a particular template expression is
to be interpreted as an integer and not as a string?
-- 
Stuart Longland (aka Redhatter, VK4MSL)

I haven't lost my mind...
  ...it's backed up on a tape somewhere.

-- 
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/256b14cc-e27a-e8a4-33a0-5e9d945673f4%40longlandclan.id.au.
For more options, visit https://groups.google.com/d/optout.

Reply via email to