How do I deploy Linodes using Ansible?

Is it possible to deploy Linode Instances with Ansible in addition to managing the configuration and software in the OS of those instances?

3 Replies

Linode support has been in Ansible for a few years. The linode module offers many of the Instance management features of the Legacy Linode API (v3).

In the most recent release of Ansible 2.8, Linode support has been updated for use with the latest Linode API (v4). Most of this work was contributed by by Luke Murphy who started the process and saw it through to the Ansible release. He's also continuing this "Linode all the things" effort on the Molecule project.

To contribute more to this project, join the Ansible Linode Working Group.

See the docs for the Linode Inventory and linode_v4 module:

Here's an example yaml file and the instructions to execute it. This example will create a Linode Nanode and will install Minecraft server on it:

  1. Create a mc.yml file using the snippet below
  2. pip install --upgrade ansible
  3. Get a Linode Personal Access Token with permission to read and write Linodes.
  4. export LINODE_TOKEN=... # Replace ... with the token
  5. ansible-playbook mc.yml -e linode_token=$LINODE_TOKEN -e type=g6-nanode-1 -e region=us-east -e image=linode/debian9 -e ssh_key=~/.ssh/
- name: launch Linode instance
  hosts: localhost
  gather_facts: False
    - name: pwd
      local_action: command pwd
    - name: spin up Linode instance
        module: linode_v4
      register: my_linode
    - name: print info about my_linode
        module: debug
          msg="ID is {{ }} IP is {{ my_linode.instance.ipv4 }}"
    - name: Add new linode to host group
        module: add_host
          hostname={{ my_linode.instance.ipv4[0] }}
    - name: Wait for SSH to come up
        module: wait_for
          host={{ my_linode.instance.ipv4[0] }}
- name: Configure linode for minecraft
  hosts: launched
  gather_facts: True
    - name: apply apt-get update --fix-missing
        update_cache: yes
        autoclean: yes
        autoremove: yes
        upgrade: dist
    - name: install Java and Screen
        update_cache: yes
        autoclean: yes
        autoremove: yes
        name: "{{ packages }}"
        - default-jdk
        - screen
    - name: make the minecraft directory
      file: state=directory path=/root/minecraft
    - name: download minecraft (1.6.4)
      command: wget chdir=/root/minecraft creates=/root/minecraft/minecraft_server.1.6.4.jar
      become_user: root
      become_method: sudo
    - name: run minecraft
      command: screen -S minecraft -d -m java -Xmx512M -Xms512M -jar /root/minecraft/minecraft_server.1.6.4.jar
      become_user: root
      become_method: sudo

It would be great to see an example where I can spin up two or three hosts and a node balancer as well.

I'm trying to do something like this:

Playbook for creating linodes and populating them.

  • name: Create group of linodes
    hosts: localhost

  • ./vars/vars.yml

  • ./vars/external.yml


  • include_tasks: create.yml

    • web-p01
    • web-p02
      loop_var: linode

And my tasks look very much like your mc.yml above, which has been a big help. Now to get it working in a loop properly
But it creates the first linode and them bombs when trying to use the 'package' module to apply patches, since I'm using CentOS8, not Debian as my install image.

I like Ansible… but I also find it annoying. LOL.

Ok, so I think I've figured it out, and my mistakes all come down to indentation. The section where you have "configure linode for minecraft" needed to be all the way left in my main task file when I called it. It's now working great.

I'll post a simple exmaple at some point I hope.


Please enter an answer

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] (

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct