mirror of https://github.com/ansible/ansible.git
hostname - add macOS (#54439)
* Add DarwinStrategy class and integration tests macOS has three seprate hostname params that need to be set. One of those params, LocalHostName, has more stringent requirements than the other two, which accept special characters and spaces. Create a method to scrub the hostname to ensure it works well with the system requirements. * Update documentation * Account for virtualization type returned on Azure Pipelines * Do not be dependent on order of self.name_types Use the scrubbed name when the name type is LocalHostNamepull/72374/head
parent
dd19c9f737
commit
7352457e7b
@ -0,0 +1,2 @@
|
|||||||
|
bugfixes:
|
||||||
|
- hostname - add macOS support (https://github.com/ansible/ansible/pull/54439)
|
@ -0,0 +1,52 @@
|
|||||||
|
- name: macOS | Set hostname
|
||||||
|
hostname:
|
||||||
|
name: bugs.acme.example.com
|
||||||
|
|
||||||
|
# These tasks can be changed to a loop once https://github.com/ansible/ansible/issues/71031
|
||||||
|
# is fixed
|
||||||
|
- name: macOS | Set hostname specifiying macos strategy
|
||||||
|
hostname:
|
||||||
|
name: bugs.acme.example.com
|
||||||
|
use: macos
|
||||||
|
|
||||||
|
- name: macOS | Set hostname specifiying macosx strategy
|
||||||
|
hostname:
|
||||||
|
name: bugs.acme.example.com
|
||||||
|
use: macosx
|
||||||
|
|
||||||
|
- name: macOS | Set hostname specifiying darwin strategy
|
||||||
|
hostname:
|
||||||
|
name: bugs.acme.example.com
|
||||||
|
use: darwin
|
||||||
|
|
||||||
|
- name: macOS | Get macOS hostname values
|
||||||
|
command: scutil --get {{ item }}
|
||||||
|
loop:
|
||||||
|
- HostName
|
||||||
|
- ComputerName
|
||||||
|
- LocalHostName
|
||||||
|
register: macos_scutil
|
||||||
|
ignore_errors: yes
|
||||||
|
|
||||||
|
- name: macOS | Ensure all hostname values were set correctly
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- "['bugs.acme.example.com', 'bugs.acme.example.com', 'bugsacmeexamplecom'] == macos_scutil.results | map(attribute='stdout') | list"
|
||||||
|
|
||||||
|
- name: macOS | Set to a hostname using spaces and punctuation
|
||||||
|
hostname:
|
||||||
|
name: The Dude's Computer
|
||||||
|
|
||||||
|
- name: macOS | Get macOS hostname values
|
||||||
|
command: scutil --get {{ item }}
|
||||||
|
loop:
|
||||||
|
- HostName
|
||||||
|
- ComputerName
|
||||||
|
- LocalHostName
|
||||||
|
register: macos_scutil_complex
|
||||||
|
ignore_errors: yes
|
||||||
|
|
||||||
|
- name: macOS | Ensure all hostname values were set correctly
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- "['The Dude\\'s Computer', 'The Dude\\'s Computer', 'The-Dudes-Computer'] == (macos_scutil_complex.results | map(attribute='stdout') | list)"
|
@ -0,0 +1,50 @@
|
|||||||
|
- name: Run hostname module in check_mode
|
||||||
|
hostname:
|
||||||
|
name: crocodile.ansible.test.doesthiswork.net.example.com
|
||||||
|
check_mode: true
|
||||||
|
register: hn1
|
||||||
|
|
||||||
|
- name: Get current hostname again
|
||||||
|
command: hostname
|
||||||
|
register: after_hn
|
||||||
|
|
||||||
|
- name: Ensure hostname changed properly
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- hn1 is changed
|
||||||
|
- original.stdout == after_hn.stdout
|
||||||
|
|
||||||
|
- when: _hostname_file is defined and _hostname_file
|
||||||
|
block:
|
||||||
|
- name: See if current hostname file exists
|
||||||
|
stat:
|
||||||
|
path: "{{ _hostname_file }}"
|
||||||
|
register: hn_stat
|
||||||
|
|
||||||
|
- name: Move the current hostname file if it exists
|
||||||
|
command: mv {{ _hostname_file }} {{ _hostname_file }}.orig
|
||||||
|
when: hn_stat.stat.exists
|
||||||
|
|
||||||
|
- name: Run hostname module in check_mode
|
||||||
|
hostname:
|
||||||
|
name: crocodile.ansible.test.doesthiswork.net.example.com
|
||||||
|
check_mode: true
|
||||||
|
register: hn
|
||||||
|
|
||||||
|
- stat:
|
||||||
|
path: /etc/rc.conf.d/hostname
|
||||||
|
register: hn_stat_checkmode
|
||||||
|
|
||||||
|
- assert:
|
||||||
|
that:
|
||||||
|
# TODO: This is a legitimate bug and will be fixed in another PR.
|
||||||
|
# - not hn_stat_checkmode.stat.exists
|
||||||
|
- hn is changed
|
||||||
|
|
||||||
|
- name: Get hostname again
|
||||||
|
command: hostname
|
||||||
|
register: current_after_cm
|
||||||
|
|
||||||
|
- assert:
|
||||||
|
that:
|
||||||
|
- original.stdout == current_after_cm.stdout
|
@ -0,0 +1,24 @@
|
|||||||
|
- name: Run hostname module for real now
|
||||||
|
hostname:
|
||||||
|
name: crocodile.ansible.test.doesthiswork.net.example.com
|
||||||
|
register: hn2
|
||||||
|
|
||||||
|
- name: Get hostname
|
||||||
|
command: hostname
|
||||||
|
register: current_after_hn2
|
||||||
|
|
||||||
|
- name: Run hostname again to ensure it does not change
|
||||||
|
hostname:
|
||||||
|
name: crocodile.ansible.test.doesthiswork.net.example.com
|
||||||
|
register: hn3
|
||||||
|
|
||||||
|
- name: Get hostname
|
||||||
|
command: hostname
|
||||||
|
register: current_after_hn3
|
||||||
|
|
||||||
|
- assert:
|
||||||
|
that:
|
||||||
|
- hn2 is changed
|
||||||
|
- hn3 is not changed
|
||||||
|
- current_after_hn2.stdout == 'crocodile.ansible.test.doesthiswork.net.example.com'
|
||||||
|
- current_after_hn2.stdout == current_after_hn2.stdout
|
Loading…
Reference in New Issue