ansible/test/integration/targets/hostname/tasks/MacOSX.yml
Sam Doran 7352457e7b
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 LocalHostName
2020-10-27 17:30:54 -04:00

52 lines
1.4 KiB
YAML

- 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)"