Skip to content

DigitalOcean Ansible dynamic inventory

Prepare

#
pamac install ansible python-digitalocean
#
ansible-galaxy collection install community.digitalocean

inventory\digitalocean.yml

plugin: community.digitalocean.digitalocean
oauth_token: "{{ lookup('ansible.builtin.env', 'DO_API_TOKEN') }}"
attributes:
  - id
  - name
  - tags
  - networks

keyed_groups:
  - key: do_tags | lower
    prefix: ""
    separator: ""

compose:
  ansible_host: do_networks.v4 | selectattr('type','eq','public') | map(attribute='ip_address') | first
  ansible_user: "'root'"

Set token

export DO_API_TOKEN=<>

Using

ansible-inventory -i inventory/digitalocean.yml --graph --vars