Hi Team,
I am creating the NAT instance using ansible scripts.
This is the NAT instance for routing traffic and jumphost, etc.
-
name: Create the NAT Instance
ec2:
region: “{{ vpc_region }}”
ec2_access_key: “{{ ec2_access_key }}”
ec2_secret_key: “{{ ec2_secret_key }}”
keypair: “{{ ec2_keypair }}”
instance_type: “{{ nat_instance_type }}”
image: “{{ nat_image }}”
vpc_subnet_id: “{{ public_subnet }}”
assign_public_ip: yes
group: “{{ vpc_name }}_sg_nat”
source_dest_check: no
wait: true
instance_tags:
Name: “{{ vpc_name }}_nat”
exact_count: 1
count_tag:
Name: “{{ vpc_name }}_nat”
register: ec2 -
name: Get the routing table entry for the main table
shell: >
{{ ec2_bin_path }}/ec2-describe-route-tables -O {{ ec2_access_key }} -W {{ ec2_secret_key }} -F vpc-id={{ vpc.vpc_id }} -F “association.main=true” | grep ROUTETABLE | awk ‘{ print $2 }’
register: main_rtb -
name: Get the NAT Instance ID and register
shell: >
{{ ec2_bin_path }}/ec2-describe-instances -O {{ ec2_access_key }} -W {{ ec2_secret_key }} -F vpc-id={{ vpc.vpc_id }} -F “instance-state-name=running” | grep “{{ vpc_name }}_nat” | awk ‘{ print $3 }’
register: nat_instance -
name: Set the gateway to nat interface.
shell: >
{{ ec2_bin_path }}/bin/ec2-create-route -O {{ ec2_access_key }} -W {{ ec2_secret_key }} {{ main_rtb.stdout }} -r 0.0.0.0/0 -i {{ nat_instance.stdout }} -
name: update subnet in the route table
shell: >
{{ ec2_bin_path }}/ec2-associate-route-table -O {{ ec2_access_key }} -W {{ ec2_secret_key }} {{ main_rtb.stdout }} -s {{ private_subnet }}
When we run the above script I am getting the error like.
TASK: [Set the gateway to nat interface.] *************************************
REMOTE_MODULE command /usr/local/ec2-api-tools/bin/ec2-create-route -O xxxxxxxxxxxxxx -W xxxxxxxxxxxxxx -r 0.0.0.0/0 -i #USE_SHELL
EXEC [’/bin/sh’, ‘-c’, ‘mkdir -p $HOME/.ansible/tmp/ansible-tmp-1460719317.22-268853804589515 && echo $HOME/.ansible/tmp/ansible-tmp-1460719317.22-268853804589515’]
PUT /tmp/tmpJ_xGn2 TO /root/.ansible/tmp/ansible-tmp-1460719317.22-268853804589515/command
EXEC [’/bin/sh’, ‘-c’, u’LANG=C LC_CTYPE=C /usr/bin/python /root/.ansible/tmp/ansible-tmp-1460719317.22-268853804589515/command; rm -rf /root/.ansible/tmp/ansible-tmp-1460719317.22-268853804589515/ >/dev/null 2>&1’]
failed: [localhost] => {“changed”: true, “cmd”: “/usr/local/ec2-api-tools/bin/ec2-create-route -O xxxxxxxxxxxxxxxxx -W xxxxxxxxxxxxxx -r 0.0.0.0/0 -i”, “delta”: “0:00:00.140411”, “end”: “2016-04-15 07:21:57.408895”, “rc”: 1, “start”: “2016-04-15 07:21:57.268484”, “warnings”: []}
stderr: Missing argument for option:i (use -h for usage)
FATAL: all hosts have already failed – aborting
PLAY RECAP ********************************************************************
to retry, use: --limit @/root/aws.retry
localhost : ok=15 changed=8 unreachable=0 failed=1
Please help me out to fix this issue. Thanks in advance