Why can't I enable private ip while creating a linode instance using linode_v4 API?

This is very inconvenient, so that I have to use some config management tool to config the network profile, reboot the machine. All those steps can be completed if private IP can be auto configured on VM creation.

7 Replies

Except you can? The docs note that if you include private_ip: true in your JSON body, you'll get assigned a private IP address during create.

nvm, it looks like the private ip is enabled and accessible from other VM, although it's not showing up in ifconfig. Closing the topic..

Please stop using ifconfig. It was obsolete 10 years ago, and has this lovely bug that will never be fixed that it does not show more than 1 IPv4 address on a given interface. The command you want to use these days is ip addr show (the "show" part can be left off if you're not supplying any additional parameters).

So the problem here is that you guys weren't clear on which API version you were using. The old v3 deprecated API does support the

private_ip: true

setting, but the new linode_v4 api does NOT support this feature. So I think you're still in the same boat of having to reboot the VM to add the private IP address.

@toshiba-it The v4 REST API does support private_ip. The original issue that I came across was because I was using the ansible module for linode and it doesn't contain many properties which are supported in the v4 REST api. Hope Linode team would update Ansible module soon so that I don't need to use lengthy uri module in Ansible to achieve what I want.

@deanmax,
Can to post an example where it works? I tried doing:

- name: Create Linode
  linode_v4:
    access_token: "{{ token }}"
    authorized_keys: "{{ ssh_keys }}"
    label: "{{ linode }}"
    region: "{{ region }}"
    type: "{{ type }}"
    image: "{{ image }}"
    root_pass: "{{ password }}"
    private_ip: true
    group: lweb_group
    tags: lweb_group
    state: present
  register: my_linode

and it bombs out saying it doesn't support that private_ip keyword.

So what I've come up with is a small task file (which I include into my main.yml playbook, but I can call with a small wrapper playbook for testing, which looks like this:

- name: "Find existing Linode(s)"
  command:
    cmd: "linode-cli linodes list --json --suppress-warnings"
  register: found_linodes
  ignore_errors: true
  changed_when: false
  delegate_to: localhost

# Show what we got back
- name: Show Linodes to check
  debug:
    msg: "Linode ID: {{ item.id }}  Label: {{ item.label }} Num ipv4: {{ (item.ipv4)|length }}"
  with_items: "{{ (found_linodes.stdout|from_json) }}"

# Only run this block when a linode doesn't have a private IP yet.
- name: Add private IP via linode-cli
  delegate_to: localhost
  command:
    cmd: "linode-cli networking ip-add --json --suppress-warnings --type ipv4 --public false --lino\
de_id {{ item.id }}"
  with_items: "{{ (found_linodes.stdout|from_json) }}"
  when: (item.ipv4)|length == 1

But I really feel like the first task should be replaced by dynamic inventory of my ansible linodes, etc. It's been hard wrapping my brain around Ansible conventions and knowing when to do stuff, and when to not bother.

I really feel like my first task up there is wrong, and how I'm using the output is a hack, but it does work. Suggestions welcome!

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct