Question

Cannot attach volume to a new droplet using ansible

Posted June 15, 2020 401 views
AnsibleUbuntu 18.04DigitalOcean Volumes

I’m trying to create and attach volumes and attach them to new droplets using Ansible.

    - name: what about the volumes?
      digital_ocean_block_storage:
        block_size: 8
        command: create
        region: 'nyc1'
        state: present
        volume_name: "{{ item }}"
      loop: "{{ droplet_tags }}"

    - name: create two droplets..
      digital_ocean_droplet:
        unique_name: yes
        region: 'nyc1'
        image: 'ubuntu-18-04-x64'
        wait_timeout: 100
        name: "{{ item }}"
        volumes: "{{ item }}"
        size: 's-1vcpu-1gb'
        state: present
      loop: "{{ droplet_tags }}"
      register: created_droplets

When I execute a playbook containing these two tasks above, I get the following error. (snippet from -vvv execution result)

failed: [localhost] (item=p6-droplet-1) => {
    "ansible_loop_var": "item", 
    "changed": false, 
    "invocation": {
        "module_args": {
            "backups": false, 
            "id": null, 
            "image": "ubuntu-18-04-x64", 
            "ipv6": false, 
            "monitoring": false, 
            "name": "p6-droplet-1", 
            "private_networking": false, 
            "region": "nyc1", 
            "size": "s-1vcpu-1gb", 
            "ssh_keys": null, 
            "tags": null, 
            "user_data": null, 
            "volumes": [
                "p6-droplet-1"
            ]
        }
    }, 
    "item": "p6-droplet-1", 
    "msg": "One or more of the provided volumes is not available in the selected region."
}
failed: [localhost] (item=p6-droplet-2) => {
    "ansible_loop_var": "item", 
    "changed": false, 
    "invocation": {
        "module_args": {
            "backups": false, 
            "id": null, 
            "image": "ubuntu-18-04-x64", 
            "ipv6": false, 
            "monitoring": false, 
            "name": "p6-droplet-2", 
            "private_networking": false, 
            "region": "nyc1", 
            "size": "s-1vcpu-1gb", 
            "ssh_keys": null, 
            "tags": null, 
            "user_data": null, 
            "volumes": [
                "p6-droplet-2"
            ]
        }
    }, 
    "item": "p6-droplet-2", 
    "msg": "One or more of the provided volumes is not available in the selected region."
}

The variable loops are working correctly, and the two volumes are already available in nyc1 region.

TASK [what about the volumes?] ********************************************************************************************************************************
ok: [localhost] => (item=p6-droplet-1) => {"ansible_loop_var": "item", "changed": false, "item": "p6-droplet-1"}
ok: [localhost] => (item=p6-droplet-2) => {"ansible_loop_var": "item", "changed": false, "item": "p6-droplet-2"}

TASK [create two droplets..] **********************************************************************************************************************************
failed: [localhost] (item=p6-droplet-1) => {"ansible_loop_var": "item", "changed": false, "item": "p6-droplet-1", "msg": "One or more of the provided volumes is not available in the selected region."}
failed: [localhost] (item=p6-droplet-2) => {"ansible_loop_var": "item", "changed": false, "item": "p6-droplet-2", "msg": "One or more of the provided volumes is not available in the selected region."}

Why am I not able to attach volumes that are in the same region? Do I have to go through extra steps? If so, what are them?

Submit an answer

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!