# Buggy code
def get_dhcp_options_info(dhcp_option):
    dhcp_option_info = {
        "DhcpOptionsId": dhcp_option["DhcpOptionsId"],
        "DhcpConfigurations": dhcp_option["DhcpConfigurations"],
        "Tags": boto3_tag_list_to_ansible_dict(dhcp_option["Tags"]),
    }
    return dhcp_option_info


# Traceback (KeyError)
TASK [Testing] *************************************************************************************************************************************************************************************************************
task path: /Users/username/devel/scratch/task-test.yml:15
Using module_utils file /Users/username/devel/ansible/lib/ansible/module_utils/basic.py
Using module_utils file /Users/username/devel/ansible/lib/ansible/module_utils/ec2.py
Using module_utils file /Users/username/devel/ansible/lib/ansible/module_utils/_text.py
Using module_utils file /Users/username/devel/ansible/lib/ansible/module_utils/pycompat24.py
Using module_utils file /Users/username/devel/ansible/lib/ansible/module_utils/six/__init__.py
Using module_utils file /Users/username/devel/ansible/lib/ansible/module_utils/six/_six.py
Using module_utils file /Users/username/devel/ansible/lib/ansible/module_utils/cloud.py
Using module file /Users/username/devel/ansible/lib/ansible/modules/cloud/amazon/ec2_vpc_dhcp_options_facts.py
<localhost> ESTABLISH LOCAL CONNECTION FOR USER: daniels
<localhost> EXEC /bin/sh -c 'echo ~ &amp;&amp; sleep 0'
<localhost> EXEC /bin/sh -c '( umask 77 &amp;&amp; mkdir -p "` echo /Users/username/.ansible/tmp/ansible-tmp-1492710436.63-94105070270006 `" &amp;&amp; echo ansible-tmp-1492710436.63-94105070270006="` echo /Users/username/.ansible/tmp/ansible-tmp-1492710436.63-94105070270006 `" ) &amp;&amp; sleep 0'
<localhost> PUT /var/folders/sk/k6tqwkbj59x4glzs2hzt2vzrbm012h/T/tmpIMSEEi TO /Users/username/.ansible/tmp/ansible-tmp-1492710436.63-94105070270006/ec2_vpc_dhcp_options_facts.py
<localhost> EXEC /bin/sh -c 'chmod u+x /Users/username/.ansible/tmp/ansible-tmp-1492710436.63-94105070270006/ /Users/username/.ansible/tmp/ansible-tmp-1492710436.63-94105070270006/ec2_vpc_dhcp_options_facts.py &amp;&amp; sleep 0'
<localhost> EXEC /bin/sh -c 'python /Users/username/.ansible/tmp/ansible-tmp-1492710436.63-94105070270006/ec2_vpc_dhcp_options_facts.py; rm -rf "/Users/username/.ansible/tmp/ansible-tmp-1492710436.63-94105070270006/" > /dev/null 2>&amp;1 &amp;&amp; sleep 0'
The full traceback is:
Traceback (most recent call last):
File "/var/folders/sk/k6tqwkbj59x4glzs2hzt2vzrbm012h/T/ansible_Xp5U7h/ansible_module_ec2_vpc_dhcp_options_facts.py", line 158, in <module>
main()
File "/var/folders/sk/k6tqwkbj59x4glzs2hzt2vzrbm012h/T/ansible_Xp5U7h/ansible_module_ec2_vpc_dhcp_options_facts.py", line 152, in main
results = list_dhcp_options(connection, module)
File "/var/folders/sk/k6tqwkbj59x4glzs2hzt2vzrbm012h/T/ansible_Xp5U7h/ansible_module_ec2_vpc_dhcp_options_facts.py", line 123, in list_dhcp_options
for option in all_dhcp_options['DhcpOptions']]
File "/var/folders/sk/k6tqwkbj59x4glzs2hzt2vzrbm012h/T/ansible_Xp5U7h/ansible_module_ec2_vpc_dhcp_options_facts.py", line 103, in get_dhcp_options_info
'Tags': boto3_tag_list_to_ansible_dict(dhcp_option['Tags'])}
KeyError: 'Tags'

fatal: [localhost]: FAILED! => {
"changed": false,
"failed": true,
"module_stderr": "Traceback (most recent call last):\n  File \"/var/folders/sk/k6tqwkbj59x4glzs2hzt2vzrbm012h/T/ansible_Xp5U7h/ansible_module_ec2_vpc_dhcp_options_facts.py\", line 158, in <module>\n    main()\n  File \"/var/folders/sk/k6tqwkbj59x4glzs2hzt2vzrbm012h/T/ansible_Xp5U7h/ansible_module_ec2_vpc_dhcp_options_facts.py\", line 152, in main\n    results = list_dhcp_options(connection, module)\n  File \"/var/folders/sk/k6tqwkbj59x4glzs2hzt2vzrbm012h/T/ansible_Xp5U7h/ansible_module_ec2_vpc_dhcp_options_facts.py\", line 123, in list_dhcp_options\n    for option in all_dhcp_options['DhcpOptions']]\n  File \"/var/folders/sk/k6tqwkbj59x4glzs2hzt2vzrbm012h/T/ansible_Xp5U7h/ansible_module_ec2_vpc_dhcp_options_facts.py\", line 103, in get_dhcp_options_info\n    'Tags': boto3_tag_list_to_ansible_dict(dhcp_option['Tags'])}\nKeyError: 'Tags'\n",
"module_stdout": "",
"msg": "MODULE FAILURE",
"rc": 0
}

# Fixed code
def get_dhcp_options_info(dhcp_option):
    dhcp_option_info = {
        "DhcpOptionsId": dhcp_option["DhcpOptionsId"],
        "DhcpConfigurations": dhcp_option["DhcpConfigurations"],
        "Tags": boto3_tag_list_to_ansible_dict(
            dhcp_option.get("Tags", [{"Value": "", "Key": "Name"}])
        ),
    }
    return dhcp_option_info