# win\_domain\_membership - Setting Hostname when No Domain Is Present

**URL:** <https://forum.ansible.com/t/win-domain-membership-setting-hostname-when-no-domain-is-present/26667>\
**Category:** Ansible Project\
**Tags:** windows\
**Created:** [February 5, 2018, 7:21pm UTC](https://forum.ansible.com/t/win-domain-membership-setting-hostname-when-no-domain-is-present/26667 "2018-02-05T19:21:16Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Justin2](https://avatars.discourse-cdn.com/v4/letter/j/d2c977/32.png) [@Justin2](https://forum.ansible.com/u/Justin2)\
**Post date:** [February 5, 2018, 7:21pm UTC](https://forum.ansible.com/t/win-domain-membership-setting-hostname-when-no-domain-is-present/26667/1 "2018-02-05T19:21:16Z")

</div>

I have a windows ec2 instance, that I would like to set the hostname on. Issue being, the module wants Domain Admin credentials which do not exist so I am not sure what is really needed here.

ansible 2.4.3.0  
config file = /home/justin/Documents/projects/ansible\_mfa/ansible.cfg  
configured module search path = [‘/home/justin/.ansible/plugins/modules’, ‘/usr/share/ansible/plugins/modules’]  
ansible python module location = /usr/lib/python3.6/site-packages/ansible  
executable location = /usr/bin/ansible  
python version = 3.6.4 (default, Jan 5 2018, 02:35:40) [GCC 7.2.1 20171224]

`

- win\_domain\_membership:  
workgroup\_name: WORKGROUP  
hostname: ‘{{ hostname }}’  
state: workgroup

`

```auto

The above indicates it needs the 'domain_admin_user' attribute, which I dont have. I attempted just putting in a bogus one. It in turn indicates it needed the 'domain_admin_password'. Is this supposed to be the
the Administrator on the local box? If so, Im not sure why I need it, when the playbook is already connected to the instance using Administrator and the proper password.

```

---

<div class="post-metadata">

**Author:** ![jborean](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/jborean/32/1525_2.png) [@jborean](https://forum.ansible.com/u/jborean)\
**Post date:** [February 6, 2018, 1:54am UTC](https://forum.ansible.com/t/win-domain-membership-setting-hostname-when-no-domain-is-present/26667/2 "2018-02-06T01:54:19Z")

</div>

The win\_domain\_membership module isn’t designed to set the hostname but rather manage whether Windows is a member of a domain or not.

It does have the added ability to set the hostname so you don’t have to do so in a separate task but that’s just an extra functionality it offers.

The reason why you need domain credentials for both state: domain and state: workgroup is that you need a domain credential to either join or a domain or leave a domain. To do what you are looking for you can do the following

`

- name: get current computer name  
win\_shell: (Get-WmiObject Win32\_ComputerSystem).CSName  
register: current\_host\_name  
changed\_when: no

- name: change hostname  
win\_shell: Rename-Computer -NewName “{{ hostname }}” -Force  
register: change\_host\_name  
when: current\_host\_name.stdout\_lines[0] != hostname

- name: restart host to apply name changes  
win\_reboot:  
when: change\_host\_name.changed  
`

Thanks

Jordan
