Here is a Linode playbook to spin a cloud server instance:
---
- hosts: 127.0.0.1
connection: local
tasks:
- name: Create Linode Machine
linode:
api_key: 'blablabla'
name: test
plan: 1
datacenter: 7
distribution: 124
password: 'blabla'
swap: 768
wait: yes
wait_timeout: 600
state: started
register: result
If I do that, the instance gets created, however this is not that great of an advantage if I can't get an ip from the output to pass to another playbook and automate a build fully.
When you run the above the module gives no output whatsoever, however if you run the playbook with the -v option, you can see that the following output is reported. How can I fetch this
changed: [127.0.0.1] => {"changed": true, "instance": {"fqdn": "xxxx.members.linode.com", "id": 2342234, "ipv4": "185.x.x.x", "name": "1902695_test", "password": "blabla", "private": [], "public": [{"fqdn": "xxxx.members.linode.com", "ip_id": 324324, "ipv4": "185.x.x.x"}], "status": "Running"}}
How can I just save the ipv4 to a variable to use in another playbook or whatever?
EDIT: I've added the following code under the one above to test the answer given but it didn't work:
- hosts: "{{ result['instance']['ipv4'] }}"
remote_user: root
tasks:
- name: "test"
command: ls -la
- apt: upgrade=dist update_cache=yes
I get the following error message:
ERROR! 'result' is undefined
Ive also tried set_fact and that didn't work either.