# Rename rax server

**URL:** <https://forum.ansible.com/t/rename-rax-server/16467>\
**Category:** Ansible Project\
**Created:** [October 8, 2014, 4:17pm UTC](https://forum.ansible.com/t/rename-rax-server/16467 "2014-10-08T16:17:22Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Graham\_Hay](https://avatars.discourse-cdn.com/v4/letter/g/59ef9b/32.png) [@Graham\_Hay](https://forum.ansible.com/u/Graham_Hay)\
**Post date:** [October 8, 2014, 4:17pm UTC](https://forum.ansible.com/t/rename-rax-server/16467/1 "2014-10-08T16:17:22Z")

</div>

Hi,

Is there any way to rename a rax server, using an ansible module? It doesn’t seem to be possible using the rax\_meta module, and I couldn’t see anything else appropriate. I can do it in the control panel easily enough, so I assume it can be done through the API.

Thanks,

Graham

---

<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:** [October 8, 2014, 4:20pm UTC](https://forum.ansible.com/t/rename-rax-server/16467/2 "2014-10-08T16:20:54Z")

</div>

There is not. You have a few options:

1. Delete it and build a new one with the new name
2. Change the name in control panel, novaclient or similar

The ‘rax’ module doesn’t make changes to the servers after they are built, but rather that the servers themselves exist or not, which is in part why rax\_meta exists for manipulating metadata at a later time.

---

<div class="post-metadata">

**Author:** ![Graham\_Hay](https://avatars.discourse-cdn.com/v4/letter/g/59ef9b/32.png) [@Graham\_Hay](https://forum.ansible.com/u/Graham_Hay)\
**Post date:** [October 8, 2014, 4:26pm UTC](https://forum.ansible.com/t/rename-rax-server/16467/3 "2014-10-08T16:26:30Z")

</div>

1. isn’t really an option (I want to rename my db replica after failover), so 2) will have to do for now. Is there any interest in adding this as a feature (somewhere)?

---

<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:** [October 8, 2014, 4:46pm UTC](https://forum.ansible.com/t/rename-rax-server/16467/4 "2014-10-08T16:46:18Z")

</div>

At this moment I’m not sure about adding it. In the end a name is just an uniqueness identifier. I personally tend to not track masters/slaves/replicas based on names, but instead check for functionality to make that determination. Connect to them all, run a check to see what they function is, use group\_by to allow for easily targeting based on that check.

I wouldn’t consider a rename as something that should happen often.

---

<div class="post-metadata">

**Author:** ![Graham\_Hay](https://avatars.discourse-cdn.com/v4/letter/g/59ef9b/32.png) [@Graham\_Hay](https://forum.ansible.com/u/Graham_Hay)\
**Post date:** [October 8, 2014, 4:58pm UTC](https://forum.ansible.com/t/rename-rax-server/16467/5 "2014-10-08T16:58:17Z")

</div>

I’m not sure I understand how that would work. Take the db example, if I want one primary and one replica, how would I go about that?

Currently, I’m using two different groups with exact\_count, which is a bit weird. If there’s a better way, I’m keen to know about it.

---

<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:** [October 8, 2014, 5:44pm UTC](https://forum.ansible.com/t/rename-rax-server/16467/6 "2014-10-08T17:44:00Z")

</div>

This is just an example, and although I haven’t run it, it seems somewhat sane.

It does the following (using fake commands as an example):

1. makes a determination of the database function of the host, by running some command that can tell you
2. creates in memory groups based on the above info using group\_by
3. targets groups in subsequent plays to ensure master and slave configurations.

This prevents you from having to record, which server is which. You check for functionality, instead of relying on potentially wrong documentation, to perform things such as replica work on replicas. Following this you could easily expand to more complicated setups, that could even be used as automated remediation when an alert is fired that a host dies.

The ‘databases’ group is a list of all database servers and is specified in inventory.

- hosts: databases

tasks:

# Example script, may return ‘master’, ‘replica’, or ‘none’

- name: Check database server functionality  
command: /usr/bin/master\_or\_replica  
register: database\_function

- name: Create in memory groups for database\_function  
group\_by: key=“database\_{{database\_function.stdout|trim}}”

- hosts: database\_none  
tasks:

- name: Add host to master group if there is no master

add\_host: name=“{{ inventory\_hostname }}” groups=database\_master  
when: groups[‘master’]|default()|len == 0

- hosts: database\_master  
tasks:

- name: Ensure master config and if needed become the master  
command: /usr/bin/config\_master

- hosts: database\_none:database\_replica  
tasks:

- name: ensure replica config  
command: /usr/bin/config\_replica  
when: inventory\_hostname != groups[‘master’][0]

This is largely how my team handles our mongodb replicaset. I don’t personally care which is the master, I just care that ansible can figure it out and performs the right tasks on the right hosts.

---

<div class="post-metadata">

**Author:** ![Graham\_Hay](https://avatars.discourse-cdn.com/v4/letter/g/59ef9b/32.png) [@Graham\_Hay](https://forum.ansible.com/u/Graham_Hay)\
**Post date:** [October 9, 2014, 8:03am UTC](https://forum.ansible.com/t/rename-rax-server/16467/7 "2014-10-09T08:03:18Z")

</div>

OK, that’s interesting, but how would I set the servers up in the first place? This isn’t a cluster that elects a leader, I need to do different setup work on the primary and replica(s). I suppose I could arbitrarily decide that the first server in the db group was the primary the first time round, but that doesn’t feel much better than my current solution.
