Update ansible-test --windows inventory creation. (#60911)
Host specific settings are created as part of the generated inventory instead of using a host_vars directory. Also update connection tests to work properly with the generated inventory changes.
This commit is contained in:
parent
e58919bccd
commit
92380d7050
14 changed files with 67 additions and 34 deletions
|
@ -1,4 +0,0 @@
|
||||||
# force 2008 to use PSRP for the connection plugin
|
|
||||||
ansible_connection: psrp
|
|
||||||
ansible_psrp_auth: basic
|
|
||||||
ansible_psrp_cert_validation: ignore
|
|
|
@ -1,4 +0,0 @@
|
||||||
# force 2016 to use NTLM + HTTP message encryption
|
|
||||||
ansible_winrm_transport: ntlm
|
|
||||||
ansible_winrm_scheme: http
|
|
||||||
ansible_port: 5985
|
|
|
@ -1,3 +0,0 @@
|
||||||
[windows:vars]
|
|
||||||
ansible_connection=psrp
|
|
||||||
ansible_psrp_cert_validation=ignore
|
|
|
@ -2,12 +2,17 @@
|
||||||
|
|
||||||
set -eux
|
set -eux
|
||||||
|
|
||||||
|
# make sure hosts are using psrp connections
|
||||||
|
ansible -i ../../inventory.winrm localhost \
|
||||||
|
-m template \
|
||||||
|
-a "src=test_connection.inventory.j2 dest=${OUTPUT_DIR}/test_connection.inventory" \
|
||||||
|
"$@"
|
||||||
|
|
||||||
python.py -m pip install pypsrp
|
python.py -m pip install pypsrp
|
||||||
cd ../connection
|
cd ../connection
|
||||||
|
|
||||||
INVENTORY=../../inventory.winrm ./test.sh \
|
INVENTORY="${OUTPUT_DIR}/test_connection.inventory" ./test.sh \
|
||||||
-i ../connection_psrp/inventory.ini \
|
-e target_hosts=windows \
|
||||||
-e target_hosts=winrm \
|
|
||||||
-e action_prefix=win_ \
|
-e action_prefix=win_ \
|
||||||
-e local_tmp=/tmp/ansible-local \
|
-e local_tmp=/tmp/ansible-local \
|
||||||
-e remote_tmp=c:/windows/temp/ansible-remote \
|
-e remote_tmp=c:/windows/temp/ansible-remote \
|
||||||
|
@ -15,5 +20,5 @@ INVENTORY=../../inventory.winrm ./test.sh \
|
||||||
|
|
||||||
cd ../connection_psrp
|
cd ../connection_psrp
|
||||||
|
|
||||||
ansible-playbook -i ../../inventory.winrm -i inventory.ini tests.yml \
|
ansible-playbook -i "${OUTPUT_DIR}/test_connection.inventory" tests.yml \
|
||||||
"$@"
|
"$@"
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
[windows]
|
||||||
|
{% for host in vars.groups.windows %}
|
||||||
|
{{ host }} ansible_host={{ hostvars[host]['ansible_host'] }} ansible_port={{ hostvars[host]['ansible_port'] }} ansible_user={{ hostvars[host]['ansible_user'] }} ansible_password={{ hostvars[host]['ansible_password'] }}
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
|
[windows:vars]
|
||||||
|
ansible_connection=psrp
|
||||||
|
ansible_psrp_auth=negotiate
|
||||||
|
ansible_psrp_cert_validation=ignore
|
|
@ -1,7 +1,7 @@
|
||||||
---
|
---
|
||||||
# these are extra tests for psrp that aren't covered under test/integration/targets/connection/*
|
# these are extra tests for psrp that aren't covered under test/integration/targets/connection/*
|
||||||
- name: test out psrp specific tests
|
- name: test out psrp specific tests
|
||||||
hosts: winrm
|
hosts: windows
|
||||||
serial: 1
|
serial: 1
|
||||||
gather_facts: no
|
gather_facts: no
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@ ansible -i ../../inventory.winrm windows \
|
||||||
"$@"
|
"$@"
|
||||||
|
|
||||||
# Need to flush the connection to ensure we get a new shell for the next tests
|
# Need to flush the connection to ensure we get a new shell for the next tests
|
||||||
ansible -i "${OUTPUT_DIR}/test_connection.inventory" windows-ssh \
|
ansible -i "${OUTPUT_DIR}/test_connection.inventory" windows \
|
||||||
-m meta -a "reset_connection" \
|
-m meta -a "reset_connection" \
|
||||||
"$@"
|
"$@"
|
||||||
|
|
||||||
|
@ -44,7 +44,7 @@ ansible -i ../../inventory.winrm windows \
|
||||||
-a "path=HKLM:\\\\SOFTWARE\\\\OpenSSH name=DefaultShell data=C:\\\\Windows\\\\System32\\\\WindowsPowerShell\\\\v1.0\\\\powershell.exe" \
|
-a "path=HKLM:\\\\SOFTWARE\\\\OpenSSH name=DefaultShell data=C:\\\\Windows\\\\System32\\\\WindowsPowerShell\\\\v1.0\\\\powershell.exe" \
|
||||||
"$@"
|
"$@"
|
||||||
|
|
||||||
ansible -i "${OUTPUT_DIR}/test_connection.inventory" windows-ssh \
|
ansible -i "${OUTPUT_DIR}/test_connection.inventory" windows \
|
||||||
-m meta -a "reset_connection" \
|
-m meta -a "reset_connection" \
|
||||||
"$@"
|
"$@"
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
[windows-ssh]
|
[windows]
|
||||||
{% for host in vars.groups.winrm %}
|
{% for host in vars.groups.windows %}
|
||||||
{{ host }} ansible_host={{ hostvars[host]['ansible_host'] }} ansible_user={{ hostvars[host]['ansible_user'] }}{{ ' ansible_ssh_private_key_file=' ~ hostvars[host]['ansible_ssh_private_key_file'] if (hostvars[host]['ansible_ssh_private_key_file']|default()) else '' }}
|
{{ host }} ansible_host={{ hostvars[host]['ansible_host'] }} ansible_user={{ hostvars[host]['ansible_user'] }}{{ ' ansible_ssh_private_key_file=' ~ hostvars[host]['ansible_ssh_private_key_file'] if (hostvars[host]['ansible_ssh_private_key_file']|default()) else '' }}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
[windows-ssh:vars]
|
[windows:vars]
|
||||||
ansible_shell_type={{ test_shell_type }}
|
ansible_shell_type={{ test_shell_type }}
|
||||||
ansible_connection=ssh
|
ansible_connection=ssh
|
||||||
ansible_port=22
|
ansible_port=22
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
---
|
---
|
||||||
- name: test out Windows SSH specific tests
|
- name: test out Windows SSH specific tests
|
||||||
hosts: windows-ssh
|
hosts: windows
|
||||||
serial: 1
|
serial: 1
|
||||||
gather_facts: no
|
gather_facts: no
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
# documented, it isn't actually used hence the separate invocation
|
# documented, it isn't actually used hence the separate invocation
|
||||||
---
|
---
|
||||||
- name: further fetch tests with metachar characters in filename
|
- name: further fetch tests with metachar characters in filename
|
||||||
hosts: windows-ssh
|
hosts: windows
|
||||||
force_handlers: yes
|
force_handlers: yes
|
||||||
serial: 1
|
serial: 1
|
||||||
gather_facts: no
|
gather_facts: no
|
||||||
|
|
|
@ -11,7 +11,7 @@ cd ../connection
|
||||||
# https://unix.stackexchange.com/questions/499958/why-does-scps-strict-filename-checking-reject-quoted-last-component-but-not-oth
|
# https://unix.stackexchange.com/questions/499958/why-does-scps-strict-filename-checking-reject-quoted-last-component-but-not-oth
|
||||||
# https://github.com/openssh/openssh-portable/commit/391ffc4b9d31fa1f4ad566499fef9176ff8a07dc
|
# https://github.com/openssh/openssh-portable/commit/391ffc4b9d31fa1f4ad566499fef9176ff8a07dc
|
||||||
INVENTORY="${OUTPUT_DIR}/test_connection.inventory" ./test.sh \
|
INVENTORY="${OUTPUT_DIR}/test_connection.inventory" ./test.sh \
|
||||||
-e target_hosts=windows-ssh \
|
-e target_hosts=windows \
|
||||||
-e action_prefix=win_ \
|
-e action_prefix=win_ \
|
||||||
-e local_tmp=/tmp/ansible-local \
|
-e local_tmp=/tmp/ansible-local \
|
||||||
-e remote_tmp=c:/windows/temp/ansible-remote \
|
-e remote_tmp=c:/windows/temp/ansible-remote \
|
||||||
|
|
|
@ -2,10 +2,16 @@
|
||||||
|
|
||||||
set -eux
|
set -eux
|
||||||
|
|
||||||
|
# make sure hosts are using winrm connections
|
||||||
|
ansible -i ../../inventory.winrm localhost \
|
||||||
|
-m template \
|
||||||
|
-a "src=test_connection.inventory.j2 dest=${OUTPUT_DIR}/test_connection.inventory" \
|
||||||
|
"$@"
|
||||||
|
|
||||||
cd ../connection
|
cd ../connection
|
||||||
|
|
||||||
INVENTORY=../../inventory.winrm ./test.sh \
|
INVENTORY="${OUTPUT_DIR}/test_connection.inventory" ./test.sh \
|
||||||
-e target_hosts=winrm \
|
-e target_hosts=windows \
|
||||||
-e action_prefix=win_ \
|
-e action_prefix=win_ \
|
||||||
-e local_tmp=/tmp/ansible-local \
|
-e local_tmp=/tmp/ansible-local \
|
||||||
-e remote_tmp=c:/windows/temp/ansible-remote \
|
-e remote_tmp=c:/windows/temp/ansible-remote \
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
[windows]
|
||||||
|
{% for host in vars.groups.windows %}
|
||||||
|
{{ host }} ansible_host={{ hostvars[host]['ansible_host'] }} ansible_port={{ hostvars[host]['ansible_port'] }} ansible_user={{ hostvars[host]['ansible_user'] }} ansible_password={{ hostvars[host]['ansible_password'] }}
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
|
[windows:vars]
|
||||||
|
ansible_connection=winrm
|
||||||
|
# we don't know if we're using an encrypted connection or not, so we'll use message encryption
|
||||||
|
ansible_winrm_transport=ntlm
|
||||||
|
ansible_winrm_server_cert_validation=ignore
|
|
@ -747,6 +747,28 @@ def windows_inventory(remotes):
|
||||||
if remote.ssh_key:
|
if remote.ssh_key:
|
||||||
options["ansible_ssh_private_key_file"] = os.path.abspath(remote.ssh_key.key)
|
options["ansible_ssh_private_key_file"] = os.path.abspath(remote.ssh_key.key)
|
||||||
|
|
||||||
|
if remote.name == 'windows-2008':
|
||||||
|
options.update(
|
||||||
|
# force 2008 to use PSRP for the connection plugin
|
||||||
|
ansible_connection='psrp',
|
||||||
|
ansible_psrp_auth='basic',
|
||||||
|
ansible_psrp_cert_validation='ignore',
|
||||||
|
)
|
||||||
|
elif remote.name == 'windows-2016':
|
||||||
|
options.update(
|
||||||
|
# force 2016 to use NTLM + HTTP message encryption
|
||||||
|
ansible_connection='winrm',
|
||||||
|
ansible_winrm_server_cert_validation='ignore',
|
||||||
|
ansible_winrm_transport='ntlm',
|
||||||
|
ansible_winrm_scheme='http',
|
||||||
|
ansible_port='5985',
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
options.update(
|
||||||
|
ansible_connection='winrm',
|
||||||
|
ansible_winrm_server_cert_validation='ignore',
|
||||||
|
)
|
||||||
|
|
||||||
hosts.append(
|
hosts.append(
|
||||||
'%s %s' % (
|
'%s %s' % (
|
||||||
remote.name.replace('/', '_'),
|
remote.name.replace('/', '_'),
|
||||||
|
@ -758,14 +780,6 @@ def windows_inventory(remotes):
|
||||||
[windows]
|
[windows]
|
||||||
%s
|
%s
|
||||||
|
|
||||||
[windows:vars]
|
|
||||||
ansible_connection=winrm
|
|
||||||
ansible_winrm_server_cert_validation=ignore
|
|
||||||
|
|
||||||
# support winrm connection tests (temporary solution, does not support testing enable/disable of pipelining)
|
|
||||||
[winrm:children]
|
|
||||||
windows
|
|
||||||
|
|
||||||
# support winrm binary module tests (temporary solution)
|
# support winrm binary module tests (temporary solution)
|
||||||
[testhost:children]
|
[testhost:children]
|
||||||
windows
|
windows
|
||||||
|
|
Loading…
Reference in a new issue