# rax\_cdb\_user not idempotent?

**URL:** <https://forum.ansible.com/t/rax-cdb-user-not-idempotent/17263>\
**Category:** Ansible Project\
**Created:** [January 14, 2015, 2:31pm UTC](https://forum.ansible.com/t/rax-cdb-user-not-idempotent/17263 "2015-01-14T14:31:21Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![David\_Goodall](https://avatars.discourse-cdn.com/v4/letter/d/67e7ee/32.png) [@David\_Goodall](https://forum.ansible.com/u/David_Goodall)\
**Post date:** [January 14, 2015, 2:31pm UTC](https://forum.ansible.com/t/rax-cdb-user-not-idempotent/17263/1 "2015-01-14T14:31:21Z")

</div>

Hi,

Using Tower 2.1 I have a playbook which creates a stack including a Cloud DB instance, user and DB.  
This works fine, but on running the playbook again, it fails with:  
msg: A user with the name “xxxxxxxxxx” already exists.  
(The username has special characters if that’s any help).

I’ve pasted the YAML for creating the DB and user below - am I missing something obvious or is this module not idempotent?

Best regards,  
David

- name: Create cloud DB server  
rax\_cdb:  
credentials: ~/.rax.creds  
region: LON  
name: “{{ db\_server }}”  
flavor: 1  
volume: 2  
wait: yes  
state: present  
register: rax\_db\_server

- name: Create cloud DB  
rax\_cdb\_database:  
credentials: ~/.rax.creds  
region: LON  
cdb\_id: “{{rax\_db\_server.cdb.id}}”  
name: “{{ db\_name }}”  
state: present  
register: rax\_db\_database

- name: Create cloud DB user  
rax\_cdb\_user:  
credentials: ~/.rax.creds  
region: LON  
cdb\_id: “{{rax\_db\_server.cdb.id}}”  
db\_username: “{{ db\_user }}”  
db\_password: “{{ db\_password }}”  
databases:

- “{{rax\_db\_database.database.name}}”  
state: present

register: rax\_db\_user

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [January 14, 2015, 4:21pm UTC](https://forum.ansible.com/t/rax-cdb-user-not-idempotent/17263/2 "2015-01-14T16:21:03Z")

</div>

I have been unable to duplicate this issue. The code in place in rax\_cdb\_user tries to perform a `instance.get_user` on the username. If the username exists the user object is returned. If an Exception is raised, the function returns False and the module attempts to create the user.

In your case, it sounds like the user does exist, but an Exception is being raised for some reason, that does not indicate the absence of a user. You could try to make the following change to rax\_cdb\_user.py (which I may do anyway):

[https://gist.github.com/sivel/3b41dd88147f7d99cab2](https://gist.github.com/sivel/3b41dd88147f7d99cab2)

If that raises some other error, it might help track down why that user cannot be found on the instance.

---

<div class="post-metadata">

**Author:** ![David\_Goodall](https://avatars.discourse-cdn.com/v4/letter/d/67e7ee/32.png) [@David\_Goodall](https://forum.ansible.com/u/David_Goodall)\
**Post date:** [January 14, 2015, 5:20pm UTC](https://forum.ansible.com/t/rax-cdb-user-not-idempotent/17263/3 "2015-01-14T17:20:00Z")

</div>

Thank you Matt.  
I made the change you suggested but still get the same result with no extra information.  
I then tried a db username with no special characters and it works fine - sorry, I should have tried this first.

Here is the db username that doesn’t work:  
S+%{r.46Z?f\_\*JuB  
The module can create a user with this name OK, but it fails on the 2nd run.  
Not a problem for me at the moment as we will just use a different name.

Thanks again for your help.  
Best regards,  
David

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [January 14, 2015, 7:34pm UTC](https://forum.ansible.com/t/rax-cdb-user-not-idempotent/17263/4 "2015-01-14T19:34:00Z")

</div>

David,

Thank you for the feedback. I will look into this and see if it is a limitation of the API, pyrax or where ever else. If I can find a solution I’ll look into applying a fix.
