mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-05-20 16:09:09 -07:00
Add windows module for changing the hostname (#40295)
Co-authored-by: Ripon Banik <riponbanik@users.noreply.github.com>
This commit is contained in:
parent
5c39c3b2d1
commit
2f70360698
6 changed files with 155 additions and 0 deletions
1
test/integration/targets/win_hostname/aliases
Normal file
1
test/integration/targets/win_hostname/aliases
Normal file
|
@ -0,0 +1 @@
|
|||
windows/ci/group3
|
2
test/integration/targets/win_hostname/defaults/main.yml
Normal file
2
test/integration/targets/win_hostname/defaults/main.yml
Normal file
|
@ -0,0 +1,2 @@
|
|||
---
|
||||
test_win_hostname_name: abcdef-123
|
18
test/integration/targets/win_hostname/tasks/main.yml
Normal file
18
test/integration/targets/win_hostname/tasks/main.yml
Normal file
|
@ -0,0 +1,18 @@
|
|||
---
|
||||
- name: get the current hostname
|
||||
win_command: hostname
|
||||
register: current_hostname
|
||||
|
||||
- block:
|
||||
- name: run tests
|
||||
include_tasks: test.yml
|
||||
|
||||
always:
|
||||
- name: reset the hostname back to the original
|
||||
win_hostname:
|
||||
name: '{{current_hostname.stdout_lines[0]}}'
|
||||
register: reset_hostname
|
||||
|
||||
- name: reboot if required
|
||||
win_reboot:
|
||||
when: reset_hostname.reboot_required
|
56
test/integration/targets/win_hostname/tasks/test.yml
Normal file
56
test/integration/targets/win_hostname/tasks/test.yml
Normal file
|
@ -0,0 +1,56 @@
|
|||
---
|
||||
- name: fail to set hostname to an invalid name
|
||||
win_hostname:
|
||||
name: invalid/name
|
||||
register: fail_hostname
|
||||
failed_when: '"Failed to rename computer to ''invalid/name''" not in fail_hostname.msg'
|
||||
|
||||
- name: change the hostname (check)
|
||||
win_hostname:
|
||||
name: '{{test_win_hostname_name}}'
|
||||
register: change_hostname_check
|
||||
check_mode: yes
|
||||
|
||||
- name: get actual hostname
|
||||
win_shell: $env:COMPUTERNAME
|
||||
register: change_hostname_actual_check
|
||||
|
||||
- name: assert change the hostname (check)
|
||||
assert:
|
||||
that:
|
||||
- change_hostname_check is changed
|
||||
- change_hostname_check.old_name|upper != test_win_hostname_name|upper
|
||||
- change_hostname_check.reboot_required
|
||||
- change_hostname_actual_check.stdout_lines[0]|upper != test_win_hostname_name|upper
|
||||
|
||||
- name: change the hostname
|
||||
win_hostname:
|
||||
name: '{{test_win_hostname_name}}'
|
||||
register: change_hostname
|
||||
|
||||
- name: reboot after changing the hostname
|
||||
win_reboot:
|
||||
|
||||
- name: get actual hostname
|
||||
win_shell: $env:COMPUTERNAME
|
||||
register: change_hostname_actual
|
||||
|
||||
- name: assert change the hostname
|
||||
assert:
|
||||
that:
|
||||
- change_hostname is changed
|
||||
- change_hostname.old_name|upper == change_hostname_check.old_name|upper
|
||||
- change_hostname.reboot_required
|
||||
- change_hostname_actual.stdout_lines[0]|upper == test_win_hostname_name|upper
|
||||
|
||||
- name: change the hostname (idempotent)
|
||||
win_hostname:
|
||||
name: '{{test_win_hostname_name}}'
|
||||
register: change_hostname_again
|
||||
|
||||
- name: assert change the hostname (idempotent)
|
||||
assert:
|
||||
that:
|
||||
- not change_hostname_again is changed
|
||||
- change_hostname_again.old_name|upper == test_win_hostname_name|upper
|
||||
- not change_hostname_again.reboot_required
|
Loading…
Add table
Add a link
Reference in a new issue