ten7.digitalocean_kubeconfig

Ansible Role: digitalocean_kubeconfig

This role helps you to get the kubeconfig for a DigitalOcean Kubernetes cluster.

When you automate tasks with DigitalOcean Kubernetes, you need a way to get the kubeconfig.yaml file, which is updated by DigitalOcean regularly for security reasons. This role uses the DigitalOcean API to fetch the kubeconfig every time you run it, ensuring you have the latest credentials.

Requirements

  • You need a DigitalOcean API key.
  • You must be able to access the DigitalOcean API.

Role Variables

Here are the variables you can set, along with their default values (located in defaults/main.yml).

API Token

digitalocean_api_token: '1234567890abscdefg'

This is your DigitalOcean API token.

Getting the kubeconfig

digitalocean_kubeconfig:
  cluster: 'my_cluster_name'
  kubeconfig: '/path/to/save/kubeconfig.yaml'

Where:

  • cluster: The name of your Kubernetes cluster.
  • kubeconfig: The location where you want to save the kubeconfig file.

Dependencies

None required.

Example Playbook

A simple example of using this role would be:

---
- hosts: cluster
  vars:
    digitalocean_api_token: "1234567890abscdefg"
    digitalocean_kubeconfig:
      cluster: "my_cluster_name"
      kubeconfig: "/path/to/save/kubeconfig.yaml"
  roles:
     - socketwench.digitalocean_kubeconfig    
  tasks:
     - name: Apply our definitions  
       k8s:
         kubeconfig: "/path/to/save/kubeconfig.yaml"
         src: "/path/to/my/k8s_definitions.yml"

If you need to write the kubeconfig to a temporary file or folder, you can use include_role or import_role in Ansible 2.x, providing the role variables in the task:

---
- hosts: cluster
  vars:
    digitalocean_api_token: '1234567890abscdefg'
  tasks:
    - name: Create a temporary directory for files
      tempfile:
        state: directory
      register: _run_temp_dir
    - name: Get the kubeconfig file.
      import_role:
        name: socketwench.digitalocean_kubeconfig
      vars:
        digitalocean_kubeconfig:
          cluster: "my_cluster_name"
          kubeconfig: "{{ _run_temp_dir.path }}/kubeconfig.yaml"
    - name: Apply our definitions  
      k8s:
        kubeconfig: "{{ _run_temp_dir.path }}/kubeconfig.yaml"
        src: "/path/to/my/k8s_definitions.yml"

License

GPL v3

Author Information

This role was created by socketwench for TEN7.

Informazioni sul progetto

Gets the kubeconfig file for clusters on DigitalOcean

Installa
ansible-galaxy install ten7.digitalocean_kubeconfig
Licenza
Unknown
Download
6.4k
Proprietario
We are a digital agency that builds, rescues and cares for Drupal sites. Our mission is to Make Things That Matter.