# create network interface (ENI) on EC2 instance? possible to use "raw" boto commands?

**URL:** <https://forum.ansible.com/t/create-network-interface-eni-on-ec2-instance-possible-to-use-raw-boto-commands/17173>\
**Category:** Ansible Project\
**Tags:** aws\
**Created:** [January 3, 2015, 12:29am UTC](https://forum.ansible.com/t/create-network-interface-eni-on-ec2-instance-possible-to-use-raw-boto-commands/17173 "2015-01-03T00:29:13Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jeff2](https://avatars.discourse-cdn.com/v4/letter/j/ebca7d/32.png) [@Jeff2](https://forum.ansible.com/u/Jeff2)\
**Post date:** [January 3, 2015, 12:29am UTC](https://forum.ansible.com/t/create-network-interface-eni-on-ec2-instance-possible-to-use-raw-boto-commands/17173/1 "2015-01-03T00:29:13Z")

</div>

Someone [asked for this](https://github.com/ansible/ansible/issues/7895) a while back before the modules were reorganized, but I’ve seen no mention since, so I’m guess it’s still not possible to create (or manipulate) an [Elastic Network Interface (eni)](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-eni.html) on an EC2 instance yet. That being the case, since this is supported by boto ([create\_network\_interface](http://boto.readthedocs.org/en/latest/ref/ec2.html#boto.ec2.connection.EC2Connection.create_network_interface)), is it possible for me to make my own calls via boto somehow? I’m not very deep into Ansible so perhaps this is a nonsensical question.

Thanks

---

<div class="post-metadata">

**Author:** ![igorc](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/igorc/32/5491_2.png) [@igorc](https://forum.ansible.com/u/igorc)\
**Post date:** [January 5, 2015, 10:37pm UTC](https://forum.ansible.com/t/create-network-interface-eni-on-ec2-instance-possible-to-use-raw-boto-commands/17173/2 "2015-01-05T22:37:10Z")

</div>

+1 for this request. Have you seen this module though: [https://github.com/cybosol/ansible/blob/master/library/cloud/ec2\_eni](https://github.com/cybosol/ansible/blob/master/library/cloud/ec2_eni)  
haven’t tried it my self but maybe it can help.

---

<div class="post-metadata">

**Author:** ![Rob\_White](https://avatars.discourse-cdn.com/v4/letter/r/71c47a/32.png) [@Rob\_White](https://forum.ansible.com/u/Rob_White)\
**Post date:** [April 15, 2015, 7:52am UTC](https://forum.ansible.com/t/create-network-interface-eni-on-ec2-instance-possible-to-use-raw-boto-commands/17173/3 "2015-04-15T07:52:19Z")

</div>

Hi guys,

Recently had this requirement myself.

I’ve written a module here [https://github.com/wimnat/ansible-modules-extras/blob/feature/ec2\_eni/cloud/amazon/ec2\_eni.py](https://github.com/wimnat/ansible-modules-extras/blob/feature/ec2_eni/cloud/amazon/ec2_eni.py)

I’d appreciate testing / feedback and if all good I’ll submit a PR to ansible-modules-extras

Thanks,

---

<div class="post-metadata">

**Author:** ![Tzach\_Livyatan1](https://avatars.discourse-cdn.com/v4/letter/t/9fc29f/32.png) [@Tzach\_Livyatan1](https://forum.ansible.com/u/Tzach_Livyatan1)\
**Post date:** [April 21, 2015, 9:23am UTC](https://forum.ansible.com/t/create-network-interface-eni-on-ec2-instance-possible-to-use-raw-boto-commands/17173/4 "2015-04-21T09:23:23Z")

</div>

Hi Rob  
Thanks for module!

I was just looking for something like this.

One thing I’m missing is the ability to set the deleteOnTermination attribute to True.  
Something like

`  
connection.modify\_network\_interface\_attribute(network\_interface.id,‘deleteOnTermination’,True, attachment\_id=network\_interface.attachment.id)

`

---

<div class="post-metadata">

**Author:** ![Rob\_White](https://avatars.discourse-cdn.com/v4/letter/r/71c47a/32.png) [@Rob\_White](https://forum.ansible.com/u/Rob_White)\
**Post date:** [April 21, 2015, 12:25pm UTC](https://forum.ansible.com/t/create-network-interface-eni-on-ec2-instance-possible-to-use-raw-boto-commands/17173/5 "2015-04-21T12:25:26Z")

</div>

Unfortunately you wouldn’t be able to create the interface with this attribute. Boto doesn’t support it. You’d have to create the interface and then immediately modify it.

Would this be acceptable?

---

<div class="post-metadata">

**Author:** ![Tzach\_Livyatan1](https://avatars.discourse-cdn.com/v4/letter/t/9fc29f/32.png) [@Tzach\_Livyatan1](https://forum.ansible.com/u/Tzach_Livyatan1)\
**Post date:** [April 22, 2015, 7:46am UTC](https://forum.ansible.com/t/create-network-interface-eni-on-ec2-instance-possible-to-use-raw-boto-commands/17173/6 "2015-04-22T07:46:37Z")

</div>

> Unfortunately you wouldn’t be able to create the interface with this attribute. Boto doesn’t support it. You’d have to create the interface and then immediately modify it.
> 
> Would this be acceptable?

Yes, this is what I’m doing now.

---

<div class="post-metadata">

**Author:** ![Rob\_White](https://avatars.discourse-cdn.com/v4/letter/r/71c47a/32.png) [@Rob\_White](https://forum.ansible.com/u/Rob_White)\
**Post date:** [April 23, 2015, 2:14am UTC](https://forum.ansible.com/t/create-network-interface-eni-on-ec2-instance-possible-to-use-raw-boto-commands/17173/7 "2015-04-23T02:14:23Z")

</div>

The latest commit has added support for delete\_on\_termination and source\_destination\_check. Please test and let me know how it goes.

If you’d like to leave any comments regarding the module, there’s a PR here [https://github.com/ansible/ansible-modules-extras/pull/410](https://github.com/ansible/ansible-modules-extras/pull/410)

---

<div class="post-metadata">

**Author:** ![Tzach\_Livyatan1](https://avatars.discourse-cdn.com/v4/letter/t/9fc29f/32.png) [@Tzach\_Livyatan1](https://forum.ansible.com/u/Tzach_Livyatan1)\
**Post date:** [April 26, 2015, 2:20pm UTC](https://forum.ansible.com/t/create-network-interface-eni-on-ec2-instance-possible-to-use-raw-boto-commands/17173/8 "2015-04-26T14:20:13Z")

</div>

> The latest commit has added support for delete\_on\_termination and source\_destination\_check. Please test and let me know how it goes.

Can you please give a full example of attaching an interface and setting the delete\_on\_termination?

Not sure how to extract the eni.interface.id for the second.

Should I use it as part of a local\_action, like I do for ec2\_tag?

Sorry for the naive questions, I’m relativity new to Ansible.

---

<div class="post-metadata">

**Author:** ![Rob\_White](https://avatars.discourse-cdn.com/v4/letter/r/71c47a/32.png) [@Rob\_White](https://forum.ansible.com/u/Rob_White)\
**Post date:** [April 26, 2015, 3:05pm UTC](https://forum.ansible.com/t/create-network-interface-eni-on-ec2-instance-possible-to-use-raw-boto-commands/17173/9 "2015-04-26T15:05:04Z")

</div>

I assume you have referenced[eni.interface.id](http://eni.interface.id) because you’ve seen the example? Note the code above that which contains a register statement. This allows you to reference output from that command. See [http://docs.ansible.com/playbooks\_variables.html](http://docs.ansible.com/playbooks_variables.html) for more on that.

Once you’ve used that register command you can reference all the values of the ENI creation.

If you’re still having issues, post your playbook as it stands and any errors you’re getting.

> The latest commit has added support for delete\_on\_termination and source\_destination\_check. Please test and let me know how it goes.

Can you please give a full example of attaching an interface and setting the delete\_on\_termination?

Not sure how to extract the [eni.interface.id](http://eni.interface.id) for the second.

Should I use it as part of a local\_action, like I do for ec2\_tag?

Sorry for the naive questions, I’m relativity new to Ansible.

---

<div class="post-metadata">

**Author:** ![Tzach\_Livyatan1](https://avatars.discourse-cdn.com/v4/letter/t/9fc29f/32.png) [@Tzach\_Livyatan1](https://forum.ansible.com/u/Tzach_Livyatan1)\
**Post date:** [April 27, 2015, 8:56am UTC](https://forum.ansible.com/t/create-network-interface-eni-on-ec2-instance-possible-to-use-raw-boto-commands/17173/10 "2015-04-27T08:56:38Z")

</div>

> I assume you have referenced[eni.interface.id](http://eni.interface.id) because you’ve seen the example? Note the code above that which contains a register statement. This allows you to reference output from that command. See [http://docs.ansible.com/playbooks\_variables.html](http://docs.ansible.com/playbooks_variables.html) for more on that.
> 
> Once you’ve used that register command you can reference all the values of the ENI creation.
> 
> If you’re still having issues, post your playbook as it stands and any errors you’re getting.

I had two issues, solve one:

- region parameter was missing, I set AWS\_REGION to solve it.  
Would it be nicer to have an explicit parameter for it, like ec2\_tag have?
- subnet\_id was missing, and I cant find an elegant way to get. For me having the instance subnet as a default will solve this problem.

---

<div class="post-metadata">

**Author:** ![Rob\_White](https://avatars.discourse-cdn.com/v4/letter/r/71c47a/32.png) [@Rob\_White](https://forum.ansible.com/u/Rob_White)\
**Post date:** [May 5, 2015, 10:19am UTC](https://forum.ansible.com/t/create-network-interface-eni-on-ec2-instance-possible-to-use-raw-boto-commands/17173/11 "2015-05-05T10:19:02Z")

</div>

The module does support region. You should be able to specify it without issue.

Can you get the subnet\_id from the ec2\_fact module?
