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
--
You received this message because you are subscribed to the Google Groups
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/68dd16d7-0896-43b2-bc6c-e219d203dc58%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.