Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with ec2_instance module error line 983, in build_volume_spec TypeError: argument of type 'NoneType' is not iterable #1452

Closed
1 task done
richardurw opened this issue Apr 5, 2023 · 4 comments

Comments

@richardurw
Copy link

Summary

When using the ec2_instance module I am see this error when running the my playbook against our AWS account.

"Traceback (most recent call last):\n File "/home/runner/.ansible/tmp/ansible-tmp-1680720676.8829982-26-232678818910360/AnsiballZ_ec2_instance.py", line 107, in \n _ansiballz_main()\n File "/home/runner/.ansible/tmp/ansible-tmp-1680720676.8829982-26-232678818910360/AnsiballZ_ec2_instance.py", line 99, in _ansiballz_main\n invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n File "/home/runner/.ansible/tmp/ansible-tmp-1680720676.8829982-26-232678818910360/AnsiballZ_ec2_instance.py", line 47, in invoke_module\n runpy.run_module(mod_name='ansible_collections.amazon.aws.plugins.modules.ec2_instance', init_globals=dict(_module_fqn='ansible_collections.amazon.aws.plugins.modules.ec2_instance', _modlib_path=modlib_path),\n File "/usr/lib64/python3.9/runpy.py", line 225, in run_module\n return _run_module_code(code, init_globals, run_name, mod_spec)\n File "/usr/lib64/python3.9/runpy.py", line 97, in _run_module_code\n _run_code(code, mod_globals, init_globals,\n File "/usr/lib64/python3.9/runpy.py", line 87, in _run_code\n exec(code, run_globals)\n File "/tmp/ansible_amazon.aws.ec2_instance_payload_r658m511/ansible_amazon.aws.ec2_instance_payload.zip/ansible_collections/amazon/aws/plugins/modules/ec2_instance.py", line 2108, in \n File "/tmp/ansible_amazon.aws.ec2_instance_payload_r658m511/ansible_amazon.aws.ec2_instance_payload.zip/ansible_collections/amazon/aws/plugins/modules/ec2_instance.py", line 2102, in main\n File "/tmp/ansible_amazon.aws.ec2_instance_payload_r658m511/ansible_amazon.aws.ec2_instance_payload.zip/ansible_collections/amazon/aws/plugins/modules/ec2_instance.py", line 1873, in ensure_present\n File "/tmp/ansible_amazon.aws.ec2_instance_payload_r658m511/ansible_amazon.aws.ec2_instance_payload.zip/ansible_collections/amazon/aws/plugins/modules/ec2_instance.py", line 1329, in build_run_instance_spec\n File "/tmp/ansible_amazon.aws.ec2_instance_payload_r658m511/ansible_amazon.aws.ec2_instance_payload.zip/ansible_collections/amazon/aws/plugins/modules/ec2_instance.py", line 983, in build_volume_spec\nTypeError: argument of type 'NoneType' is not iterable\n",

Issue Type

Bug Report

Component Name

ec2_instance

Ansible Version

ansible [core 2.14.2]
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.9/site-packages/ansible
  ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
  executable location = /bin/ansible
  python version = 3.9.13 (main, Nov  9 2022, 13:16:24) [GCC 8.5.0 20210514 (Red Hat 8.5.0-15)] (/usr/bin/python3.9)
  jinja version = 3.1.2
  libyaml = True

Collection Versions

# /usr/share/ansible/collections/ansible_collections
Collection      Version
--------------- -------
amazon.aws      5.4.0  
ansible.windows 1.10.0 
community.aws   5.4.0  

# /root/.ansible/collections/ansible_collections
Collection      Version
--------------- -------
amazon.aws      5.4.0  
ansible.utils   2.9.0  
ansible.windows 1.13.0 
community.aws   5.4.0  

AWS SDK versions

WARNING: Package(s) not found: boto
Name: boto3
Version: 1.26.99
Summary: The AWS SDK for Python
Home-page: https://github.com/boto/boto3
Author: Amazon Web Services
Author-email: None
License: Apache License 2.0
Location: /usr/local/lib/python3.9/site-packages
Requires: s3transfer, botocore, jmespath
Required-by: 
---
Name: botocore
Version: 1.29.99
Summary: Low-level, data-driven core of boto 3.
Home-page: https://github.com/boto/botocore
Author: Amazon Web Services
Author-email: None
License: Apache License 2.0
Location: /usr/local/lib/python3.9/site-packages
Requires: urllib3, jmespath, python-dateutil
Required-by: s3transfer, boto3

Configuration

CONFIG_FILE() = /etc/ansible/ansible.cfg
DEFAULT_EXECUTABLE(/etc/ansible/ansible.cfg) = /bin/sh
DEFAULT_ROLES_PATH(/etc/ansible/ansible.cfg) = ['/root/.ansible/roles', '/usr/share/ansible/roles', '/etc/ansible/roles']

OS / Environment

RHEL 8.6

Steps to Reproduce

 - name: EC2 privisoning 
    amazon.aws.ec2_instance:
      key_name: #####
      count: "{{ i_count }}"
      security_groups: "{{ security_group }}" ### To attach existing security group uncomment this line if commented.
      instance_type: "{{ i_type }}"
      instance_role: "{{ i_iam_role }}"
      image_id: ami-0a68ff873cf4a3c9b
      wait: yes
      wait_timeout: 500
      volumes:
        - device_name: /dev/sda1
          ebs:
          volume_type: gp3
          volume_size: "{{ i_vol }}"
          delete_on_termination: "{{ i_vol_term }}"
        - device_name: /dev/xvdf
          ebs:
          volume_type: gp3
          volume_size: "{{ i_vol2 }}"
          delete_on_termination: "{{ i_vol_term }}" 
      vpc_subnet_id: "{{ aws_vpc_subnet_id }}"
      user_data: "{{ lookup('template', 'userdata.linux.j2') }}"    
      # count_tag:
      #     Name: "{{ i_name }}"
      # exact_count: "{{ i_count }}"

    register: ec2
 
  
  - name: Tag EC2 Instances          
    amazon.aws.ec2_tag:  
      resource: "{{ item.id }}"
      tags:
        Name: "{{ i_name }}"
        AppOwner: "{{ i_appowner }}"
        AppName: "{{ i_appname }}"
        Environment: "{{ i_env }}"
        map-migrated: "d-server-022367eo3j8i56"
        Builtby: "Ansible"
        OSType: "Linux"

    # loop: "{{ ec2.instances }}" 

  #- name: Wait for volume to be available
  #  pause:
  #    minutes: 3

Expected Results

I expected the playbook to successfully deploy an ec2 instance but it did not.

Actual Results

Using module file /usr/share/ansible/collections/ansible_collections/amazon/aws/plugins/modules/ec2_instance.py
<localhost> PUT /home/runner/.ansible/tmp/ansible-local-211zxrh67a/tmp22n6kxrd TO /home/runner/.ansible/tmp/ansible-tmp-1680720676.8829982-26-232678818910360/AnsiballZ_ec2_instance.py
<localhost> EXEC /bin/sh -c 'chmod u+x /home/runner/.ansible/tmp/ansible-tmp-1680720676.8829982-26-232678818910360/ /home/runner/.ansible/tmp/ansible-tmp-1680720676.8829982-26-232678818910360/AnsiballZ_ec2_instance.py && sleep 0'
<localhost> EXEC /bin/sh -c '/usr/bin/python3.9 /home/runner/.ansible/tmp/ansible-tmp-1680720676.8829982-26-232678818910360/AnsiballZ_ec2_instance.py && sleep 0'
<localhost> EXEC /bin/sh -c 'rm -f -r /home/runner/.ansible/tmp/ansible-tmp-1680720676.8829982-26-232678818910360/ > /dev/null 2>&1 && sleep 0'
The full traceback is:
Traceback (most recent call last):
  File "/home/runner/.ansible/tmp/ansible-tmp-1680720676.8829982-26-232678818910360/AnsiballZ_ec2_instance.py", line 107, in <module>
    _ansiballz_main()
  File "/home/runner/.ansible/tmp/ansible-tmp-1680720676.8829982-26-232678818910360/AnsiballZ_ec2_instance.py", line 99, in _ansiballz_main
    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
  File "/home/runner/.ansible/tmp/ansible-tmp-1680720676.8829982-26-232678818910360/AnsiballZ_ec2_instance.py", line 47, in invoke_module
    runpy.run_module(mod_name='ansible_collections.amazon.aws.plugins.modules.ec2_instance', init_globals=dict(_module_fqn='ansible_collections.amazon.aws.plugins.modules.ec2_instance', _modlib_path=modlib_path),
  File "/usr/lib64/python3.9/runpy.py", line 225, in run_module
    return _run_module_code(code, init_globals, run_name, mod_spec)

Code of Conduct

  • I agree to follow the Ansible Code of Conduct
@richardurw
Copy link
Author

richardurw commented Apr 5, 2023

Found out why its throwing the error. New ec2_instance module doesn't require the parameter to list volume type. It seems like it defaults to gp3 automatically for EC2 instance creation.

@richardurw richardurw reopened this Apr 6, 2023
@richardurw
Copy link
Author

richardurw commented Apr 6, 2023

Actually after more trial and error volume type parameter isn't the issue that is the reason why its throwing the error. Looks to be something else in the ec2_instance.py code it keeps referring to. It only happens when I run my playbook against and ec2 linux instance. If anyone have seen this before let me know.

Thanks

@richardurw richardurw changed the title Issue with ec2_instance module Issue with ec2_instance module error line 983, in build_volume_spec TypeError: argument of type 'NoneType' is not iterable Apr 6, 2023
@richardurw
Copy link
Author

richardurw commented Apr 10, 2023

Wanted to add the same playbook works when deploying a windows ec2 instance to AWS. Only effecting linux ec2 deployments when I set a specific volumes details. I am not iterating anything but yet its complaining about NoneType is not iterable. Works if I leave out the volume details and let it choose the defaults.

@richardurw
Copy link
Author

Figured it out. Indentation issue with ebs line in volumes.

abikouo pushed a commit to abikouo/amazon.aws that referenced this issue Sep 18, 2023
Migrate rds_instance* modules and tests

Depends-On: ansible-collections#1011
Depends-On: ansible-collections#1480
Remove rds_instance* modules and tests
These modules have been migrated to amazon.aws
Update runtime.yml with redirects to that collection
Update ignore files

Reviewed-by: Mike Graves <[email protected]>
Reviewed-by: Bikouo Aubin <None>
Reviewed-by: Mark Chappell <None>
abikouo pushed a commit to abikouo/amazon.aws that referenced this issue Sep 18, 2023
Migrate rds_instance* modules and tests

Depends-On: ansible-collections#1011
Depends-On: ansible-collections#1480
Remove rds_instance* modules and tests
These modules have been migrated to amazon.aws
Update runtime.yml with redirects to that collection
Update ignore files

Reviewed-by: Mike Graves <[email protected]>
Reviewed-by: Bikouo Aubin <None>
Reviewed-by: Mark Chappell <None>
abikouo pushed a commit to abikouo/amazon.aws that referenced this issue Oct 24, 2023
Migrate rds_instance* modules and tests

Depends-On: ansible-collections#1011
Depends-On: ansible-collections#1480
Remove rds_instance* modules and tests
These modules have been migrated to amazon.aws
Update runtime.yml with redirects to that collection
Update ignore files

Reviewed-by: Mike Graves <[email protected]>
Reviewed-by: Bikouo Aubin <None>
Reviewed-by: Mark Chappell <None>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant