win_domain_membership - Setting Hostname when No Domain Is Present

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

`


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.

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