Giter VIP home page Giter VIP logo

upcloud-ansible-collection's Introduction

Ansible UpCloud Collection

Ansible sanity tests unit tests

UpCloud inventory as a modernized Ansible collection. Current scope only covers UpCloud's servers offering, but depending on the demand we might include our other services (networks, (object) storages, routers, databases etc) in it as well. Same goes for plugins for other API actions. We recommend using Terraform for automated management of your UpCloud infrastructure, but we might implement some server control plugins for Ansible in the future if the demand is there.

If you find yourself needing a specific service as an inventory, please open an issue. Please see the development & contribution sections below for development quickstart if you're interested in adding new features or making fixes.

Getting Started

Prerequisites

UpCloud Collection requires UpCloud API's Python bindings version 2.5.0 or newer in order to work. It can be installed from the Python Package Index with the pip tool:

pip3 install upcloud-api>=2.5.0

The collection itself can be installed with the ansible-galaxy command that comes with the Ansible package:

ansible-galaxy collection install https://github.com/UpCloudLtd/upcloud-ansible-collection/releases/download/v0.6.0/community-upcloud-0.6.0.tar.gz

Inventory usage

Inventory file must be named so that it ends either in upcloud.yml or upcloud.yaml. It is also possible to filter servers based on their zone, tags, state, or the network they belong to.

Quick Start

Create an upcloud.yml file with these contents:

plugin: community.upcloud.upcloud

Set environment variables for API authentication:

export UPCLOUD_USERNAME="upcloud-api-access-enabled-user"
export UPCLOUD_PASSWORD="verysecretpassword"

And show the Ansible inventory information as a graph:

ansible-inventory -i upcloud.yml --graph --vars

You should see a list of hosts and their host variables you can use in playbooks.

Further examples

You can filter based on multiple data points:

plugin: community.upcloud.upcloud
zones:
  - fi-hel2
labels:
  - role=prod
  - foo
states:
  - started
connect_with: private_ipv4
network: 035a0a8a-7704-4da5-820d-129fc8232714
server_group: Group name or UUID

Servers can also be grouped by status, zone etc by specifying them as keyed_groups.

plugin: community.upcloud.upcloud
keyed_groups:
  - key: zone
    prefix: upcloud_zone
  - key: state
    prefix: server_state

Examples here assume that API credentials are available as environment variables (UPCLOUD_USERNAME & UPCLOUD_PASSWORD). They can also be defined in inventory file:

plugin: community.upcloud.upcloud
username: YOUR_USERNAME
password: YOUR_PASSWORD

Troubleshooting

If you are having problems loading, finding or enabling the collection, you might need to create or modify your existing ansible.cfgconfig. Adding the following settings should ensure that the collection can be found and is enabled:

[default]
collections_paths = ~/.ansible/collections:/usr/share/ansible/collections

[inventory]
enable_plugins = community.upcloud.upcloud

Note that, if you are using any other plugins, those should be listed in enable_plugins as well.

Changelog

Changelog is available in its own file.

Development

This collection follows Ansible Developer Guide, with the exception that Python 2.7 is not supported as the support has been dropped from UpCloud's Python SDK.

All functionality should include relevant tests.

Tests can be run with ansible-test tool (comes with Ansible) in the collection folder (default: ~/.ansible/collections/ansible_collections/community/upcloud):

$ cd ~/.ansible/collections/ansible_collections/community/upcloud
$ ansible-test sanity --docker -v --color
...
$ ansible-test units -v --color --docker --coverage
...

Building and installing a new version locally

A new version can be built and tested locally with the ansible-galaxy tool that is packaged with Ansible.

ansible-galaxy collection build
ansible-galaxy collection install community-upcloud-<VERSION>.tar.gz

upcloud-ansible-collection's People

Contributors

ajmyyra avatar darep avatar kangasta avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

upcloud-ansible-collection's Issues

Using collection stops ansible from using IP address with the -i argument

Calling the command below works without the collection,
ansible-playbook -u root -i '94.237.xxx.xx,' app.yml
Adding it produces this:

[WARNING]: Unable to parse 94.237.xxx.xx, as an inventory source
[WARNING]: No inventory was parsed, only implicit localhost is available
[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'

Provide ansible_distribution when building inventory

Hi,

We would need to know beforehand if a host if Windows, or Debain or CentOS, this way we can put them in appropriate groups.

For sure windows needs to be divided from the other hosts since other connection parameters are needed when using Ansible.

It would be great if more information of the server was specified.

Worst case just having the initial template name would be a great step forward ;)

Atm this is quite blocking to get 100% automation...

Invalid value "community.upcloud.upcloud"

Seems like the bug in UpCloudLtd/upcloud-ansible#36 is still present

ansible-inventory -i test-upcloud.yml  --graph
[WARNING]:  * Failed to parse /ansible/test-upcloud.yml with ansible_collections.community.upcloud.plugins.inventory.upcloud plugin: Invalid value "community.upcloud.upcloud" for configuration option "plugin_type: inventory plugin:
ansible_collections.community.upcloud.plugins.inventory.upcloud setting: plugin ", valid values are: ['upcloud']

file test-upcloud.yml
plugin: community.upcloud.upcloud

Trying to use use_vars_plugins

It would be great if this was supported: ansible/ansible#44382

An extra param: use_vars_plugins: true

(Check the last comments in the thread)

It would then be possible to load existing host variables into the class (from host_vars/hostname.yml) and make groups with them.

Give a better error message when using an older/deprecated upcloud-sdk

Edit: as per below, the problem was the SDK that was on version 1.0.1 when ~2.0 is required. This needs a better error message than crashing with the "unable to parse inventory" error.

======

I installed the collection with galaxy as instructed

My inventory file is:

plugin: community.upcloud.upcloud
tags:
  - swarm

my ansible.cfg is:

[default]
collections_paths = ~/.ansible/collections:/usr/share/ansible/collections

[inventory]
enable_plugins = community.upcloud.upcloud

Result:

ansible git:(main) โœ— ansible-inventory --list -i inventory/upcloud.yaml
[WARNING]:  * Failed to parse /Users/patrickleblanc/ansible/inventory/upcloud.yaml with ansible_collections.community.upcloud.plugins.inventory.upcloud plugin: 'str' object has no
attribute 'user_agent'
[WARNING]: Unable to parse /Users/patrickleblanc/ansible/inventory/upcloud.yaml as an inventory source
[WARNING]: No inventory was parsed, only implicit localhost is available

Any idea what I'm doing wrong?

No fallback if server has no public ipv4

Hi,

When we try to get all the servers in upcloud the default is to throw an exception if a server has no public interface at all.

This is quite unfortunate, it's very well possible there are a couple of 100 servers and only a few have no public ipv4 interface. This should not throw a fatal error but just leave the host empty.

An even better alternative is trying to fallback to the private ip address... Since it's most likely the best option when no public ipv4 is found. At least it's nice to have the private address which can possible used over a VPN or an ssh tunnel.

I implemented such change here: https://github.com/HOSTED-POWER/upcloud-ansible-collection/blob/main/plugins/inventory/upcloud.py

I think it's really needed, the current design breaks completely as soon as one host has no public ipv4 address.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.