From 319cc80a9fdcc846b5b53e75b18254da37949d83 Mon Sep 17 00:00:00 2001 From: "Dustin C. Hatch" Date: Sun, 26 Jan 2025 07:03:26 -0600 Subject: [PATCH] inventory: Configure for HostVDS openstack Using the Ansible OpenStack inventory plugin, we can automatically fetch information about running instances in HostVDS. We're deriving group membership from the `groups` metadata tag. The OpenStack API password must be specified in a `secure.yaml` file. We're omitting this from the repository because there's no apparent way to encrypt it. The inventory plugin tends to prefer IPv6 addresses over IPv4 when populating `ansible_host`, even if the control machine does not have IPv6 connectivity. Thus, we have to compose the relevant variables ourselves with a Jinja2 expression. --- .gitignore | 2 ++ clouds.yaml | 9 +++++++++ hostvds.openstack.yml | 18 ++++++++++++++++++ 3 files changed, 29 insertions(+) create mode 100644 clouds.yaml create mode 100644 hostvds.openstack.yml diff --git a/.gitignore b/.gitignore index 2f1273a..59040e0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,7 @@ +/.inventory-cache /.vault-secret.gpg .fact-cache +/secure.yaml /victoria-metrics-*.tar.gz /victoria-metrics-*/ /tmp/ diff --git a/clouds.yaml b/clouds.yaml new file mode 100644 index 0000000..a6038e2 --- /dev/null +++ b/clouds.yaml @@ -0,0 +1,9 @@ +clouds: + hostvds: + region_name: us-east2 + auth: + username: hostvds-b3897be3-8920-4fb0-955d-340a162da6dd + project_name: hostvds-b3897be3-8920-4fb0-955d-340a162da6dd + auth_url: https://os-api.hostvds.com/identity + user_domain_name: Default + project_domain_id: default diff --git a/hostvds.openstack.yml b/hostvds.openstack.yml new file mode 100644 index 0000000..f349180 --- /dev/null +++ b/hostvds.openstack.yml @@ -0,0 +1,18 @@ +plugin: openstack.cloud.openstack +only_clouds: +- hostvds +cache: true +cache_plugin: jsonfile +cache_connection: .inventory-cache +compose: + ansible_user: '"root"' + ansible_host: &ipv4 + (openstack.addresses[openstack.addresses|first] + | selectattr('version', 'eq', 4) + | first + ).addr + ansible_ssh_host: *ipv4 +keyed_groups: +- key: openstack.metadata.groups|split(',') + prefix: '' + separator: ''