Wrong Linode ID with the linode Module

Please im relatively new with ansiible and having an issue.

Using the Linode Module to Create a new Linode instance. The Instance is created but with the wrong linode_id

  • name: Create linode machine
    linode:
    api_key: ‘My_Api_key’
    name: server
    plan: 1
    datacenter: 7
    distribution: 140
    password: ‘Some_password’
    linode_id: 12345678
    ssh_pub_key: ‘s…’
    wait: yes
    wait_timeout: 600
    state: present

I assume the Linode instance is supposed to have an Id of 12345678, but that’s not the Linode ID of the created instance. It’s been set to an arbitrary numeric value.

Please how do i correct this?

This is sort of a bug with ansible because the linode role is not idempotent.
I think there are pull requests to fix this in ansible v2, but for the time being
you will mostly likely have to work around it.

The linode_id does not set the ID at linode. It is to target that linode server
if you need to remove or change it. This means there is no linode_id when
first create it.

So to work around this issue you need to comment out the ID on first run.
Then you need to most likely need to add this to your linode task:
register: linode_server then add a new task to - debug: var=linode_server
this way you can see the ID that is created. Copy that ID into linode_id on
for the next runs of the playbook to be idempotent. Hopefully they can fix this
soon.

This is sort of a bug with ansible because the linode role is not
idempotent.
I think there are pull requests to fix this in ansible v2, but for the time
being
you will mostly likely have to work around it.

Check:
https://github.com/ansible/ansible-modules-core/search?q=linode&type=Issues

If you don't find an issue or PR here, feel free to file one.

--g

Thanks for the reply. Would use the work around.

Also created an Issue on this as none existed.

One More thing please, Is it possible that after i
`register: linode_server

I set a varriable to the linode_id value to be used in another playbook?

register: linode_return

you should have the linode id as part of that variable.

Indeed. I actually write the ID to a file and then use {{ lookup(“file”, “path/to/id”) }} later in the playbook. This way I can use it after the playbook finishes in subsequent runs and in other playbooks.

Brian Coca wrote:

you can even write to host_vars/linode_host

linode_id: 2134234

and it becomes a hostvar that is automatically loaded associated to that host.

My goodness!Ansible indeed rocks. Issue resolved, plus i understand things better now!
Thanks Guys

For archival Purposes ,

I modified my task thus:

also

- debug: var=linode_return

to just see it on screen