Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update ansible-test --windows inventory creation. #60911

Merged
merged 3 commits into from Aug 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 0 additions & 4 deletions test/integration/host_vars/windows-2008

This file was deleted.

4 changes: 0 additions & 4 deletions test/integration/host_vars/windows-2016

This file was deleted.

3 changes: 0 additions & 3 deletions test/integration/targets/connection_psrp/inventory.ini

This file was deleted.

13 changes: 9 additions & 4 deletions test/integration/targets/connection_psrp/runme.sh
Expand Up @@ -2,18 +2,23 @@

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
cd ../connection

INVENTORY=../../inventory.winrm ./test.sh \
-i ../connection_psrp/inventory.ini \
-e target_hosts=winrm \
INVENTORY="${OUTPUT_DIR}/test_connection.inventory" ./test.sh \
-e target_hosts=windows \
-e action_prefix=win_ \
-e local_tmp=/tmp/ansible-local \
-e remote_tmp=c:/windows/temp/ansible-remote \
"$@"

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
2 changes: 1 addition & 1 deletion test/integration/targets/connection_psrp/tests.yml
@@ -1,7 +1,7 @@
---
# these are extra tests for psrp that aren't covered under test/integration/targets/connection/*
- name: test out psrp specific tests
hosts: winrm
hosts: windows
serial: 1
gather_facts: no

Expand Down
4 changes: 2 additions & 2 deletions test/integration/targets/connection_windows_ssh/runme.sh
Expand Up @@ -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
ansible -i "${OUTPUT_DIR}/test_connection.inventory" windows-ssh \
ansible -i "${OUTPUT_DIR}/test_connection.inventory" windows \
-m meta -a "reset_connection" \
"$@"

Expand All @@ -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" \
"$@"

ansible -i "${OUTPUT_DIR}/test_connection.inventory" windows-ssh \
ansible -i "${OUTPUT_DIR}/test_connection.inventory" windows \
-m meta -a "reset_connection" \
"$@"

Expand Down
@@ -1,9 +1,9 @@
[windows-ssh]
{% for host in vars.groups.winrm %}
[windows]
{% 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 '' }}
{% endfor %}

[windows-ssh:vars]
[windows:vars]
ansible_shell_type={{ test_shell_type }}
ansible_connection=ssh
ansible_port=22
Expand Down
2 changes: 1 addition & 1 deletion test/integration/targets/connection_windows_ssh/tests.yml
@@ -1,6 +1,6 @@
---
- name: test out Windows SSH specific tests
hosts: windows-ssh
hosts: windows
serial: 1
gather_facts: no

Expand Down
Expand Up @@ -3,7 +3,7 @@
# documented, it isn't actually used hence the separate invocation
---
- name: further fetch tests with metachar characters in filename
hosts: windows-ssh
hosts: windows
force_handlers: yes
serial: 1
gather_facts: no
Expand Down
2 changes: 1 addition & 1 deletion test/integration/targets/connection_windows_ssh/windows.sh
Expand Up @@ -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://github.com/openssh/openssh-portable/commit/391ffc4b9d31fa1f4ad566499fef9176ff8a07dc
INVENTORY="${OUTPUT_DIR}/test_connection.inventory" ./test.sh \
-e target_hosts=windows-ssh \
-e target_hosts=windows \
-e action_prefix=win_ \
-e local_tmp=/tmp/ansible-local \
-e remote_tmp=c:/windows/temp/ansible-remote \
Expand Down
10 changes: 8 additions & 2 deletions test/integration/targets/connection_winrm/runme.sh
Expand Up @@ -2,10 +2,16 @@

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

INVENTORY=../../inventory.winrm ./test.sh \
-e target_hosts=winrm \
INVENTORY="${OUTPUT_DIR}/test_connection.inventory" ./test.sh \
-e target_hosts=windows \
-e action_prefix=win_ \
-e local_tmp=/tmp/ansible-local \
-e remote_tmp=c:/windows/temp/ansible-remote \
Expand Down
@@ -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
30 changes: 22 additions & 8 deletions test/lib/ansible_test/_internal/executor.py
Expand Up @@ -747,6 +747,28 @@ def windows_inventory(remotes):
if remote.ssh_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(
'%s %s' % (
remote.name.replace('/', '_'),
Expand All @@ -758,14 +780,6 @@ def windows_inventory(remotes):
[windows]
%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)
[testhost:children]
windows
Expand Down