By nhyun
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?
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Hello,
The issue might be that the creation and attachment of the volumes are asynchronous operations that are still in progress when you try to create the droplets. This would make the volumes not yet available for attachment, resulting in the error message you’re seeing.
One way to handle this in your Ansible playbook is to introduce a delay or a wait_for task after the volume creation, giving the volumes enough time to be fully created and become available for attachment. The wait_for module can pause the playbook execution for a set amount of time, or until a certain condition is met.
Here’s an example of how to introduce a delay:
- 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: Wait for volume to be available
wait_for:
timeout: 60
sleep: 5
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
This introduces a delay of up to 60 seconds after each volume creation, waiting 5 seconds between each check. You can adjust the timeout and sleep values accordingly.
Best,
Bobby
Heya,
Just came across this answer and decided to write some general guidelines for anyone who comes across this in the future despite the old question.
It seems like the volume is not available for the droplet to attach to or its identifiers might not be correct. Keep in mind that a volume’s name is different from its ID, and it’s the ID that you should use to refer to a volume in your playbook.
Ensure that you are using the correct ID of the volume when attaching them to the droplets and that they are in an available state before the droplets are created.
Check in the DigitalOcean dashboard or by running doctl compute volume list to ensure the existence and state of the volume.
If the issue continues, please share your complete playbook and any defined variables or parameter files you might be using. Exclude any sensitive information such as token ids, passwords, etc.
For more information on using Ansible with DigitalOcean, check out this link - Ansible.
Hope that this helps!
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.