Difference between revisions of "Deploy Scaleway Servers with Ansible"

From Knowledge Center
Jump to: navigation, search
(Created page with "Export your API Token: <pre> $ export SCW_TOKEN='XXX' </pre> Playbook: <pre> --- - name: Test compute instance lifecycle on a Scaleway account hosts: localhost gather_f...")
 
(No difference)

Latest revision as of 02:51, 20 March 2019

Export your API Token:

$ export SCW_TOKEN='XXX'

Playbook:

---
- name: Test compute instance lifecycle on a Scaleway account
  hosts: localhost
  gather_facts: no
  environment:
    SCW_API_KEY: "your-api-key"

  tasks:
    - name: create manager
      register: server_creation_task1
      scaleway_compute:
        name: swarm-manager
        state: present
        image: 710ff1fa-0d16-4f8f-93ac-0647c44fa21d
        organization: your-orga-id
        region: ams1
        commercial_type: START1-M
        wait: true

    - debug: var=server_creation_task1
    - debug: msg="{{server_creation_task1.msg.hostname}}"

    - assert:
        that:
          - server_creation_task1 is success
          - server_creation_task1 is changed

    - name: run manager
      scaleway_compute:
        name: swarm-manager
        state: running
        image: 710ff1fa-0d16-4f8f-93ac-0647c44fa21d
        organization: your-orga-id
        region: ams1
        commercial_type: START1-M
        wait: true
        tags:
          - swarm
      register: server_run_task1

    - debug: var=server_run_task1
    - debug: msg="{{server_run_task1.msg.public_ip}}"

    - assert:
        that:
          - server_run_task1 is success
          - server_run_task1 is changed

Example ansible.cfg:

[defaults]
host_key_checking = False
executable = /bin/bash
force_color = 1
inventory = ./hosts
remote_user = root
private_key_file= /Users/ruan/.ssh/id_rsa

Run the playbook:

$ ansible-playbook -u ruan scw.yml

Create the scaleway inventory file:

---
plugin: scaleway
regions:
  - ams1
  - par1
tags:
  - swarm
hostnames:
  - hostname
variables:
  external_ip: public_ip.address
  state: state

Get the public ip of your server:

$ ansible-inventory --list -i scw_inventory.yml  | jq -r '._meta.hostvars."swarm-manager".external_ip'