# Digital\_ocean\_droplet - can not target a specific project

**URL:** <https://forum.ansible.com/t/digital-ocean-droplet-can-not-target-a-specific-project/2692>\
**Category:** Get Help\
**Tags:** digitalocean\
**Created:** [December 1, 2023, 1:02pm UTC](https://forum.ansible.com/t/digital-ocean-droplet-can-not-target-a-specific-project/2692 "2023-12-01T13:02:16Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![dulhaver](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/dulhaver/32/1061_2.png) [@dulhaver](https://forum.ansible.com/u/dulhaver)\
**Post date:** [December 1, 2023, 1:02pm UTC](https://forum.ansible.com/t/digital-ocean-droplet-can-not-target-a-specific-project/2692/1 "2023-12-01T13:02:16Z")

</div>

I am playing with `digital_ocean_droplet` and can manage to create one, but fail doing this into any but the default project.

There is a default project named `devops_bootcamp`, but I want, for testing purposes, create the droplet into the initial `first-project` (which still exists, but is not the default any longer)

```yml
---
- hosts: localhost
  connection: local
  become: false
  vars_files:
    - ./do_api_token.yml
  tasks:
    - name: show variable values
      ansible.builtin.debug:
        msg: |
          "drop_name: {{ drop_name }}
           project_name: {{ project }}"

    - name: Create a new Droplet
      community.digitalocean.digital_ocean_droplet:
        state: "{{ state }}"
        oauth_token: "{{ DO_API_TOKEN }}"
        name: "{{ drop_name }}"
        size: s-1vcpu-512mb-10gb
        region: fra1
        image: "{{ distro_image | default('debian-12-x64') }}"
        wait_timeout: 500
        project_name: "{{ project }}"
        ssh_keys: ['a5:a3:b9:50:e6:c1:a8:0f:b9:70:6a:d9:56:78:91:d4']
      register: drop_var
      when: state == 'present'

    - name: Show Droplet info
      ansible.builtin.debug:
        var: drop_var      

```

… which I run like

```bash
ansible-playbook do_droplet.yml \
    -e '{ "state":"present" , "drop_name":"drop-40" , "project":"first-project" }' \
    --ask-vault-pass

```

so, the droplet gets created, but inside the default project `"devops-bootcamp"`, not `"first-project"`, as intended.

any idea what is wrong here?

* * *

I am getting confirmation the variable value is passed into the run correctly by that `show variable values` TASK

```auto
2023-12-01 13:51:57,618 p=116936 u=dulhaver n=ansible | ok: [127.0.0.1] => 
  msg: |-
    "drop_name: drop-40
     project_name: first-project"

```

---

<div class="post-metadata">

**Author:** ![ptn](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/ptn/32/481_2.png) [@ptn](https://forum.ansible.com/u/ptn)\
**Post date:** [December 2, 2023, 12:21pm UTC](https://forum.ansible.com/t/digital-ocean-droplet-can-not-target-a-specific-project/2692/2 "2023-12-02T12:21:39Z")

</div>

Hi,

I don’t do much python, but looking at `create()` function in module definition, specifically [the project assignment part](https://github.com/ansible-collections/community.digitalocean/blob/main/plugins/modules/digital_ocean_droplet.py#L782), I fail to see why it shouldn’t work.  
Here is the [`assign_to_project()` function definition](https://github.com/ansible-collections/community.digitalocean/blob/b5290f81e24b606b624ace6e2cd752a6f10a3ac4/plugins/module_utils/digital_ocean.py#L227) if you’d like to delve deeper.

Could you run you playbook in verbose mode (`-vvv` should be plenty), see if module returns an error somewhere on project assignment ?  
Function should return an error if: project is not set, doesn’t have an id, can’t be assigned for whatever reason, or there is an issue with resource (droplet data), though I’m not sure a) it isn’t catched, and b) if it breaks.

Also, interestingly enough, there are similar issues on community.digitalocean repo: [#255](https://github.com/ansible-collections/community.digitalocean/issues/255#issuecomment-1124383186), [#201](https://github.com/ansible-collections/community.digitalocean/issues/201#issuecomment-1123166176) which states using `project` keyword (which is just an alias) in you task definition instead of `project_name` works. Perplexing. I’m thinking it has to do with how parameters are defined in module specs, and the alias is used in `create()` function instead of the param name, but as said earlier, I’m not a python nor Ansible module expert, so I’ll let someone else chime on that.

I know that’s not what you asked, but as a workaround, you could probably [update your target project to set it as default](https://docs.ansible.com/ansible/latest/collections/community/digitalocean/digital_ocean_project_module.html#parameter-is_default) (or [from DO API](https://docs.digitalocean.com/reference/api/api-reference/#operation/projects_patch)) (assuming droplet module always follows default project), create your droplet and let it be assigned to that project, then rollback your projects statuses. Not very elegant, but should do the trick for the meantime. Or just directly assign your droplet to project using [this DO API endpoint](https://docs.digitalocean.com/reference/api/api-reference/#operation/projects_assign_resources) and [ansible.builtin.uri module](https://docs.ansible.com/ansible/latest/collections/ansible/builtin/uri_module.html).
