Add integration test targets for core supported modules (#24217)
A preliminary set of test targets for "core" supported module that had no independent tests. These will also help us ensure python3 compatibility for those modules and prevent future regressions.
This commit is contained in:
parent
a5020a40e5
commit
e9c2546ffe
45 changed files with 1118 additions and 0 deletions
1
test/integration/targets/apt_key/aliases
Normal file
1
test/integration/targets/apt_key/aliases
Normal file
|
@ -0,0 +1 @@
|
|||
posix/ci/group1
|
2
test/integration/targets/apt_key/meta/main.yml
Normal file
2
test/integration/targets/apt_key/meta/main.yml
Normal file
|
@ -0,0 +1,2 @@
|
|||
dependencies:
|
||||
- prepare_tests
|
19
test/integration/targets/apt_key/tasks/apt_key.yml
Normal file
19
test/integration/targets/apt_key/tasks/apt_key.yml
Normal file
|
@ -0,0 +1,19 @@
|
|||
- name: run first docs example
|
||||
apt_key:
|
||||
keyserver: keyserver.ubuntu.com
|
||||
id: 36A1D7869245C8950F966E92D8576A8BA88D21E9
|
||||
register: apt_key_test0
|
||||
- debug: var=apt_key_test0
|
||||
|
||||
- name: re-run first docs example
|
||||
apt_key:
|
||||
keyserver: keyserver.ubuntu.com
|
||||
id: 36A1D7869245C8950F966E92D8576A8BA88D21E9
|
||||
register: apt_key_test1
|
||||
|
||||
- name: validate results
|
||||
assert:
|
||||
that:
|
||||
- 'apt_key_test0.changed is defined'
|
||||
- 'apt_key_test0.changed'
|
||||
- 'not apt_key_test1.changed'
|
28
test/integration/targets/apt_key/tasks/main.yml
Normal file
28
test/integration/targets/apt_key/tasks/main.yml
Normal file
|
@ -0,0 +1,28 @@
|
|||
# Test code for the apt_key module.
|
||||
# (c) 2017, James Tanner <tanner.jc@gmail.com>
|
||||
|
||||
# This file is part of Ansible
|
||||
#
|
||||
# Ansible is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# Ansible is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
- set_fact: output_dir_test={{output_dir}}/apt_key
|
||||
|
||||
- name: make sure our testing sub-directory does not exist
|
||||
file: path="{{ output_dir_test }}" state=absent
|
||||
|
||||
- name: create our testing sub-directory
|
||||
file: path="{{ output_dir_test }}" state=directory
|
||||
|
||||
- include: 'apt_key.yml'
|
||||
when: ansible_distribution in ('Ubuntu', 'Debian')
|
1
test/integration/targets/at/aliases
Normal file
1
test/integration/targets/at/aliases
Normal file
|
@ -0,0 +1 @@
|
|||
posix/ci/group1
|
2
test/integration/targets/at/meta/main.yml
Normal file
2
test/integration/targets/at/meta/main.yml
Normal file
|
@ -0,0 +1,2 @@
|
|||
dependencies:
|
||||
- prepare_tests
|
62
test/integration/targets/at/tasks/main.yml
Normal file
62
test/integration/targets/at/tasks/main.yml
Normal file
|
@ -0,0 +1,62 @@
|
|||
# Test code for the at module.
|
||||
# (c) 2017, James Tanner <tanner.jc@gmail.com>
|
||||
|
||||
# This file is part of Ansible
|
||||
#
|
||||
# Ansible is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# Ansible is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
- set_fact: output_dir_test={{output_dir}}/at
|
||||
|
||||
- name: make sure our testing sub-directory does not exist
|
||||
file: path="{{ output_dir_test }}" state=absent
|
||||
|
||||
- name: create our testing sub-directory
|
||||
file: path="{{ output_dir_test }}" state=directory
|
||||
|
||||
##
|
||||
## at
|
||||
##
|
||||
|
||||
- name: define distros to attempt installing at on
|
||||
set_fact:
|
||||
package_distros:
|
||||
- RedHat
|
||||
- CentOS
|
||||
- ScientificLinux
|
||||
- Fedora
|
||||
- Ubuntu
|
||||
- Debian
|
||||
- openSUSE Leap
|
||||
|
||||
- name: ensure at is installed
|
||||
package:
|
||||
name: at
|
||||
state: present
|
||||
when: ansible_distribution in package_distros
|
||||
|
||||
- name: run the first example
|
||||
at:
|
||||
command: "ls -d / > /dev/null"
|
||||
count: 20
|
||||
units: minutes
|
||||
register: at_test0
|
||||
- debug: var=at_test0
|
||||
- name: validate results
|
||||
assert:
|
||||
that:
|
||||
- 'at_test0.changed is defined'
|
||||
- 'at_test0.count is defined'
|
||||
- 'at_test0.script_file is defined'
|
||||
- 'at_test0.state is defined'
|
||||
- 'at_test0.units is defined'
|
1
test/integration/targets/blockinfile/aliases
Normal file
1
test/integration/targets/blockinfile/aliases
Normal file
|
@ -0,0 +1 @@
|
|||
posix/ci/group1
|
135
test/integration/targets/blockinfile/files/sshd_config
Normal file
135
test/integration/targets/blockinfile/files/sshd_config
Normal file
|
@ -0,0 +1,135 @@
|
|||
# $OpenBSD: sshd_config,v 1.100 2016/08/15 12:32:04 naddy Exp $
|
||||
|
||||
# This is the sshd server system-wide configuration file. See
|
||||
# sshd_config(5) for more information.
|
||||
|
||||
# This sshd was compiled with PATH=/usr/local/bin:/usr/bin
|
||||
|
||||
# The strategy used for options in the default sshd_config shipped with
|
||||
# OpenSSH is to specify options with their default value where
|
||||
# possible, but leave them commented. Uncommented options override the
|
||||
# default value.
|
||||
|
||||
# If you want to change the port on a SELinux system, you have to tell
|
||||
# SELinux about this change.
|
||||
# semanage port -a -t ssh_port_t -p tcp #PORTNUMBER
|
||||
#
|
||||
#Port 22
|
||||
#AddressFamily any
|
||||
#ListenAddress 0.0.0.0
|
||||
#ListenAddress ::
|
||||
|
||||
HostKey /etc/ssh/ssh_host_rsa_key
|
||||
#HostKey /etc/ssh/ssh_host_dsa_key
|
||||
HostKey /etc/ssh/ssh_host_ecdsa_key
|
||||
HostKey /etc/ssh/ssh_host_ed25519_key
|
||||
|
||||
# Ciphers and keying
|
||||
#RekeyLimit default none
|
||||
|
||||
# Logging
|
||||
#SyslogFacility AUTH
|
||||
SyslogFacility AUTHPRIV
|
||||
#LogLevel INFO
|
||||
|
||||
# Authentication:
|
||||
|
||||
#LoginGraceTime 2m
|
||||
PermitRootLogin yes
|
||||
#StrictModes yes
|
||||
#MaxAuthTries 6
|
||||
#MaxSessions 10
|
||||
|
||||
#PubkeyAuthentication yes
|
||||
|
||||
# The default is to check both .ssh/authorized_keys and .ssh/authorized_keys2
|
||||
# but this is overridden so installations will only check .ssh/authorized_keys
|
||||
AuthorizedKeysFile .ssh/authorized_keys
|
||||
|
||||
#AuthorizedPrincipalsFile none
|
||||
|
||||
#AuthorizedKeysCommand none
|
||||
#AuthorizedKeysCommandUser nobody
|
||||
|
||||
# For this to work you will also need host keys in /etc/ssh/ssh_known_hosts
|
||||
#HostbasedAuthentication no
|
||||
# Change to yes if you don't trust ~/.ssh/known_hosts for
|
||||
# HostbasedAuthentication
|
||||
#IgnoreUserKnownHosts no
|
||||
# Don't read the user's ~/.rhosts and ~/.shosts files
|
||||
#IgnoreRhosts yes
|
||||
|
||||
# To disable tunneled clear text passwords, change to no here!
|
||||
#PermitEmptyPasswords no
|
||||
|
||||
# Change to no to disable s/key passwords
|
||||
#ChallengeResponseAuthentication yes
|
||||
ChallengeResponseAuthentication no
|
||||
|
||||
# Kerberos options
|
||||
#KerberosAuthentication no
|
||||
#KerberosOrLocalPasswd yes
|
||||
#KerberosTicketCleanup yes
|
||||
#KerberosGetAFSToken no
|
||||
#KerberosUseKuserok yes
|
||||
|
||||
# GSSAPI options
|
||||
GSSAPIAuthentication yes
|
||||
GSSAPICleanupCredentials no
|
||||
#GSSAPIStrictAcceptorCheck yes
|
||||
#GSSAPIKeyExchange no
|
||||
#GSSAPIEnablek5users no
|
||||
|
||||
# Set this to 'yes' to enable PAM authentication, account processing,
|
||||
# and session processing. If this is enabled, PAM authentication will
|
||||
# be allowed through the ChallengeResponseAuthentication and
|
||||
# PAM authentication via ChallengeResponseAuthentication may bypass
|
||||
# the setting of "PermitRootLogin without-password".
|
||||
# If you just want the PAM account and session checks to run without
|
||||
# and ChallengeResponseAuthentication to 'no'.
|
||||
# WARNING: 'UsePAM no' is not supported in Fedora and may cause several
|
||||
# problems.
|
||||
UsePAM yes
|
||||
|
||||
#AllowAgentForwarding yes
|
||||
#AllowTcpForwarding yes
|
||||
#GatewayPorts no
|
||||
X11Forwarding yes
|
||||
#X11DisplayOffset 10
|
||||
#X11UseLocalhost yes
|
||||
#PermitTTY yes
|
||||
#PrintMotd yes
|
||||
#PrintLastLog yes
|
||||
#TCPKeepAlive yes
|
||||
#UseLogin no
|
||||
#UsePrivilegeSeparation sandbox
|
||||
#PermitUserEnvironment no
|
||||
#Compression delayed
|
||||
#ClientAliveInterval 0
|
||||
#ClientAliveCountMax 3
|
||||
#ShowPatchLevel no
|
||||
#UseDNS no
|
||||
#PidFile /var/run/sshd.pid
|
||||
#MaxStartups 10:30:100
|
||||
#PermitTunnel no
|
||||
#ChrootDirectory none
|
||||
#VersionAddendum none
|
||||
|
||||
# no default banner path
|
||||
#Banner none
|
||||
|
||||
# Accept locale-related environment variables
|
||||
AcceptEnv LANG LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY LC_MESSAGES
|
||||
AcceptEnv LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE LC_MEASUREMENT
|
||||
AcceptEnv LC_IDENTIFICATION LC_ALL LANGUAGE
|
||||
AcceptEnv XMODIFIERS
|
||||
|
||||
# override default of no subsystems
|
||||
Subsystem sftp /usr/libexec/openssh/sftp-server
|
||||
|
||||
# Example of overriding settings on a per-user basis
|
||||
#Match User anoncvs
|
||||
# X11Forwarding no
|
||||
# AllowTcpForwarding no
|
||||
# PermitTTY no
|
||||
# ForceCommand cvs server
|
2
test/integration/targets/blockinfile/meta/main.yml
Normal file
2
test/integration/targets/blockinfile/meta/main.yml
Normal file
|
@ -0,0 +1,2 @@
|
|||
dependencies:
|
||||
- prepare_tests
|
67
test/integration/targets/blockinfile/tasks/main.yml
Normal file
67
test/integration/targets/blockinfile/tasks/main.yml
Normal file
|
@ -0,0 +1,67 @@
|
|||
# Test code for the blockinfile module.
|
||||
# (c) 2017, James Tanner <tanner.jc@gmail.com>
|
||||
|
||||
# This file is part of Ansible
|
||||
#
|
||||
# Ansible is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# Ansible is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
- set_fact: output_dir_test={{output_dir}}/test_blockinfile
|
||||
|
||||
- name: make sure our testing sub-directory does not exist
|
||||
file: path="{{ output_dir_test }}" state=absent
|
||||
|
||||
- name: create our testing sub-directory
|
||||
file: path="{{ output_dir_test }}" state=directory
|
||||
|
||||
##
|
||||
## blockinfile
|
||||
##
|
||||
|
||||
- name: copy the sshd_config to the test dir
|
||||
copy:
|
||||
src: sshd_config
|
||||
dest: "{{ output_dir_test }}"
|
||||
|
||||
- name: insert/update "Match User" configuration block in sshd_config
|
||||
blockinfile:
|
||||
path: "{{ output_dir_test }}/sshd_config"
|
||||
block: |
|
||||
Match User ansible-agent
|
||||
PasswordAuthentication no
|
||||
register: blockinfile_test0
|
||||
- name: check content
|
||||
shell: 'grep -e "Match User ansible-agent" -e "PasswordAuthentication no" {{ output_dir_test }}/sshd_config'
|
||||
register: blockinfile_test0_grep
|
||||
- debug: var=blockinfile_test0
|
||||
- debug: var=blockinfile_test0_grep
|
||||
- name: validate first example results
|
||||
assert:
|
||||
that:
|
||||
- 'blockinfile_test0.changed is defined'
|
||||
- 'blockinfile_test0.msg is defined'
|
||||
- 'blockinfile_test0.changed'
|
||||
- 'blockinfile_test0.msg == "Block inserted"'
|
||||
- 'blockinfile_test0_grep.stdout_lines | length == 2'
|
||||
|
||||
- name: check idemptotence
|
||||
blockinfile:
|
||||
path: "{{ output_dir_test }}/sshd_config"
|
||||
block: |
|
||||
Match User ansible-agent
|
||||
PasswordAuthentication no
|
||||
register: blockinfile_test1
|
||||
- name: validate idempotence results
|
||||
assert:
|
||||
that:
|
||||
- 'not blockinfile_test1.changed'
|
1
test/integration/targets/debconf/aliases
Normal file
1
test/integration/targets/debconf/aliases
Normal file
|
@ -0,0 +1 @@
|
|||
posix/ci/group1
|
2
test/integration/targets/debconf/meta/main.yml
Normal file
2
test/integration/targets/debconf/meta/main.yml
Normal file
|
@ -0,0 +1,2 @@
|
|||
dependencies:
|
||||
- prepare_tests
|
36
test/integration/targets/debconf/tasks/main.yml
Normal file
36
test/integration/targets/debconf/tasks/main.yml
Normal file
|
@ -0,0 +1,36 @@
|
|||
# Test code for the debconf module.
|
||||
# (c) 2017, James Tanner <tanner.jc@gmail.com>
|
||||
|
||||
# This file is part of Ansible
|
||||
#
|
||||
# Ansible is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# Ansible is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
##
|
||||
## debconf query
|
||||
##
|
||||
|
||||
- block:
|
||||
- name: query the tzdata package
|
||||
debconf:
|
||||
name: tzdata
|
||||
register: debconf_test0
|
||||
|
||||
- name: validate results for test 0
|
||||
assert:
|
||||
that:
|
||||
- 'debconf_test0.changed is defined'
|
||||
- 'debconf_test0.current is defined'
|
||||
- '"tzdata/Zones/Etc" in debconf_test0.current'
|
||||
- 'debconf_test0.current["tzdata/Zones/Etc"] == "UTC"'
|
||||
when: ansible_distribution in ('Ubuntu', 'Debian')
|
1
test/integration/targets/find/aliases
Normal file
1
test/integration/targets/find/aliases
Normal file
|
@ -0,0 +1 @@
|
|||
posix/ci/group1
|
2
test/integration/targets/find/meta/main.yml
Normal file
2
test/integration/targets/find/meta/main.yml
Normal file
|
@ -0,0 +1,2 @@
|
|||
dependencies:
|
||||
- prepare_tests
|
83
test/integration/targets/find/tasks/main.yml
Normal file
83
test/integration/targets/find/tasks/main.yml
Normal file
|
@ -0,0 +1,83 @@
|
|||
# Test code for the find module.
|
||||
# (c) 2017, James Tanner <tanner.jc@gmail.com>
|
||||
|
||||
# This file is part of Ansible
|
||||
#
|
||||
# Ansible is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# Ansible is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
- set_fact: output_dir_test={{output_dir}}/test_find
|
||||
|
||||
- name: make sure our testing sub-directory does not exist
|
||||
file: path="{{ output_dir_test }}" state=absent
|
||||
|
||||
- name: create our testing sub-directory
|
||||
file: path="{{ output_dir_test }}" state=directory
|
||||
|
||||
##
|
||||
## find
|
||||
##
|
||||
|
||||
- name: make some directories
|
||||
file:
|
||||
path: "{{ output_dir_test }}/{{ item }}"
|
||||
state: directory
|
||||
with_items:
|
||||
- a/b/c/d
|
||||
- e/f/g/h
|
||||
|
||||
- name: make some files
|
||||
copy:
|
||||
dest: "{{ output_dir_test }}/{{ item }}"
|
||||
content: 'data'
|
||||
with_items:
|
||||
- a/1.txt
|
||||
- a/b/2.jpg
|
||||
- a/b/c/3
|
||||
- a/b/c/d/4.xml
|
||||
- e/5.json
|
||||
- e/f/6.swp
|
||||
- e/f/g/7.img
|
||||
- e/f/g/h/8.ogg
|
||||
|
||||
- name: find the directories
|
||||
find:
|
||||
paths: "{{ output_dir_test }}"
|
||||
file_type: directory
|
||||
recurse: yes
|
||||
register: find_test0
|
||||
- debug: var=find_test0
|
||||
- name: validate directory results
|
||||
assert:
|
||||
that:
|
||||
- 'find_test0.changed is defined'
|
||||
- 'find_test0.examined is defined'
|
||||
- 'find_test0.files is defined'
|
||||
- 'find_test0.matched is defined'
|
||||
- 'find_test0.msg is defined'
|
||||
- 'find_test0.matched == 8'
|
||||
- 'find_test0.files | length == 8'
|
||||
|
||||
- name: find the xml and img files
|
||||
find:
|
||||
paths: "{{ output_dir_test }}"
|
||||
file_type: file
|
||||
patterns: "*.xml,*.img"
|
||||
recurse: yes
|
||||
register: find_test1
|
||||
- debug: var=find_test1
|
||||
- name: validate directory results
|
||||
assert:
|
||||
that:
|
||||
- 'find_test1.matched == 2'
|
||||
- 'find_test1.files | length == 2'
|
1
test/integration/targets/getent/aliases
Normal file
1
test/integration/targets/getent/aliases
Normal file
|
@ -0,0 +1 @@
|
|||
posix/ci/group1
|
2
test/integration/targets/getent/meta/main.yml
Normal file
2
test/integration/targets/getent/meta/main.yml
Normal file
|
@ -0,0 +1,2 @@
|
|||
dependencies:
|
||||
- prepare_tests
|
38
test/integration/targets/getent/tasks/main.yml
Normal file
38
test/integration/targets/getent/tasks/main.yml
Normal file
|
@ -0,0 +1,38 @@
|
|||
# Test code for the getent module.
|
||||
# (c) 2017, James Tanner <tanner.jc@gmail.com>
|
||||
|
||||
# This file is part of Ansible
|
||||
#
|
||||
# Ansible is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# Ansible is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
- name: check for getent command
|
||||
shell: which getent
|
||||
failed_when: False
|
||||
register: getent_check
|
||||
##
|
||||
## getent
|
||||
##
|
||||
- block:
|
||||
- name: run the first example
|
||||
getent:
|
||||
database: passwd
|
||||
key: root
|
||||
register: getent_test0
|
||||
- debug: var=getent_test0
|
||||
- name: validate results
|
||||
assert:
|
||||
that:
|
||||
- 'getent_passwd is defined'
|
||||
- 'getent_passwd.root is defined'
|
||||
- 'getent_passwd.root|length == 6'
|
||||
when: getent_check.rc == 0
|
1
test/integration/targets/group/aliases
Normal file
1
test/integration/targets/group/aliases
Normal file
|
@ -0,0 +1 @@
|
|||
posix/ci/group1
|
20
test/integration/targets/group/files/grouplist.sh
Normal file
20
test/integration/targets/group/files/grouplist.sh
Normal file
|
@ -0,0 +1,20 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
#- name: make a list of groups
|
||||
# shell: |
|
||||
# cat /etc/group | cut -d: -f1
|
||||
# register: group_names
|
||||
# when: 'ansible_distribution != "MacOSX"'
|
||||
|
||||
#- name: make a list of groups [mac]
|
||||
# shell: dscl localhost -list /Local/Default/Groups
|
||||
# register: group_names
|
||||
# when: 'ansible_distribution == "MacOSX"'
|
||||
|
||||
DISTRO="$*"
|
||||
|
||||
if [[ "$DISTRO" == "MacOSX" ]]; then
|
||||
dscl localhost -list /Local/Default/Groups
|
||||
else
|
||||
egrep -v ^\# /etc/group | cut -d: -f1
|
||||
fi
|
2
test/integration/targets/group/meta/main.yml
Normal file
2
test/integration/targets/group/meta/main.yml
Normal file
|
@ -0,0 +1,2 @@
|
|||
dependencies:
|
||||
- prepare_tests
|
107
test/integration/targets/group/tasks/main.yml
Normal file
107
test/integration/targets/group/tasks/main.yml
Normal file
|
@ -0,0 +1,107 @@
|
|||
# Test code for the group module.
|
||||
# (c) 2017, James Tanner <tanner.jc@gmail.com>
|
||||
|
||||
# This file is part of Ansible
|
||||
#
|
||||
# Ansible is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# Ansible is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
- name: get the jinja2 version
|
||||
shell: python -c 'import jinja2; print(jinja2.__version__)'
|
||||
register: jinja2_version
|
||||
delegate_to: localhost
|
||||
- debug: var=jinja2_version
|
||||
|
||||
##
|
||||
## group add
|
||||
##
|
||||
|
||||
- name: try to create group
|
||||
group:
|
||||
name: ansibullgroup
|
||||
state: present
|
||||
register: group_test0
|
||||
|
||||
- name: make a list of groups
|
||||
script: grouplist.sh "{{ ansible_distribution }}"
|
||||
register: group_names
|
||||
|
||||
- name: show group names
|
||||
debug: var=group_names
|
||||
- name: validate results for testcase 0
|
||||
assert:
|
||||
that:
|
||||
- '"ansibullgroup" in group_names.stdout_lines'
|
||||
|
||||
##
|
||||
## group check
|
||||
##
|
||||
|
||||
- name: run existing group check tests
|
||||
group:
|
||||
name: "{{ group_names.stdout_lines|random }}"
|
||||
state: present
|
||||
with_sequence: start=1 end=5
|
||||
register: group_test1
|
||||
- debug: var=group_test1
|
||||
|
||||
- name: validate results for testcase 1
|
||||
assert:
|
||||
that:
|
||||
- 'group_test1.results is defined'
|
||||
- 'group_test1.results|length == 5'
|
||||
|
||||
- name: validate change results for testcase 1 (jinja2 >= 2.6)
|
||||
assert:
|
||||
that:
|
||||
- "group_test1.results|map(attribute='changed')|unique|list == [False]"
|
||||
- "group_test1.results|map(attribute='state')|unique|list == ['present']"
|
||||
when: "jinja2_version.stdout|version_compare('2.6', '>=')"
|
||||
|
||||
- name: validate change results for testcase 1 (jinja2 < 2.6)
|
||||
assert:
|
||||
that:
|
||||
- "not group_test1.results[0]['changed']"
|
||||
- "not group_test1.results[1]['changed']"
|
||||
- "not group_test1.results[2]['changed']"
|
||||
- "not group_test1.results[3]['changed']"
|
||||
- "not group_test1.results[4]['changed']"
|
||||
when: "jinja2_version.stdout|version_compare('2.6', '<')"
|
||||
|
||||
|
||||
|
||||
##
|
||||
## group remove
|
||||
##
|
||||
|
||||
- name: try to delete the group
|
||||
group:
|
||||
name: ansibullgroup
|
||||
state: absent
|
||||
register: group_test2
|
||||
|
||||
- name: make a new list of groups
|
||||
shell: |
|
||||
cat /etc/group | cut -d: -f1
|
||||
register: group_names2
|
||||
when: 'ansible_distribution != "MacOSX"'
|
||||
|
||||
- name: make a list of groups
|
||||
script: grouplist.sh "{{ ansible_distribution }}"
|
||||
register: group_names2
|
||||
|
||||
- debug: var=group_names2
|
||||
- name: validate results for testcase 2
|
||||
assert:
|
||||
that:
|
||||
- '"ansibullgroup" not in group_names2.stdout_lines'
|
5
test/integration/targets/iso_extract/aliases
Normal file
5
test/integration/targets/iso_extract/aliases
Normal file
|
@ -0,0 +1,5 @@
|
|||
posix/ci/group1
|
||||
needs/privileged
|
||||
needs/root
|
||||
skip/freebsd
|
||||
skip/osx
|
BIN
test/integration/targets/iso_extract/files/test.iso
Normal file
BIN
test/integration/targets/iso_extract/files/test.iso
Normal file
Binary file not shown.
2
test/integration/targets/iso_extract/meta/main.yml
Normal file
2
test/integration/targets/iso_extract/meta/main.yml
Normal file
|
@ -0,0 +1,2 @@
|
|||
dependencies:
|
||||
- prepare_tests
|
45
test/integration/targets/iso_extract/tasks/main.yml
Normal file
45
test/integration/targets/iso_extract/tasks/main.yml
Normal file
|
@ -0,0 +1,45 @@
|
|||
# Test code for the iso_extract module.
|
||||
# (c) 2017, James Tanner <tanner.jc@gmail.com>
|
||||
|
||||
# This file is part of Ansible
|
||||
#
|
||||
# Ansible is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# Ansible is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
- set_fact: output_dir_test={{output_dir}}/test_command_raw
|
||||
|
||||
- name: make sure our testing sub-directory does not exist
|
||||
file: path="{{ output_dir_test }}" state=absent
|
||||
|
||||
- name: create our testing sub-directory
|
||||
file: path="{{ output_dir_test }}" state=directory
|
||||
|
||||
##
|
||||
## iso_extract
|
||||
##
|
||||
|
||||
- name: copy the iso to the test dir
|
||||
copy:
|
||||
src: test.iso
|
||||
dest: "{{ output_dir_test }}"
|
||||
|
||||
- name: extract the iso
|
||||
iso_extract:
|
||||
image: "{{ output_dir_test }}/test.iso"
|
||||
dest: "{{ output_dir_test }}"
|
||||
files:
|
||||
- 1.txt
|
||||
- 2.txt
|
||||
register: iso_extract_test0
|
||||
|
||||
# FIXME - fill this in after figuring out how to allow mounts
|
1
test/integration/targets/package/aliases
Normal file
1
test/integration/targets/package/aliases
Normal file
|
@ -0,0 +1 @@
|
|||
posix/ci/group1
|
2
test/integration/targets/package/meta/main.yml
Normal file
2
test/integration/targets/package/meta/main.yml
Normal file
|
@ -0,0 +1,2 @@
|
|||
dependencies:
|
||||
- prepare_tests
|
68
test/integration/targets/package/tasks/main.yml
Normal file
68
test/integration/targets/package/tasks/main.yml
Normal file
|
@ -0,0 +1,68 @@
|
|||
# Test code for the package module.
|
||||
# (c) 2017, James Tanner <tanner.jc@gmail.com>
|
||||
|
||||
# This file is part of Ansible
|
||||
#
|
||||
# Ansible is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# Ansible is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
- set_fact: output_dir_test={{output_dir}}/at
|
||||
|
||||
- name: make sure our testing sub-directory does not exist
|
||||
file: path="{{ output_dir_test }}" state=absent
|
||||
|
||||
- name: create our testing sub-directory
|
||||
file: path="{{ output_dir_test }}" state=directory
|
||||
|
||||
##
|
||||
## package
|
||||
##
|
||||
|
||||
- name: define distros to attempt installing at on
|
||||
set_fact:
|
||||
package_distros:
|
||||
- RedHat
|
||||
- CentOS
|
||||
- ScientificLinux
|
||||
- Fedora
|
||||
- Ubuntu
|
||||
- Debian
|
||||
|
||||
- block:
|
||||
- name: remove at package
|
||||
package:
|
||||
name: at
|
||||
state: absent
|
||||
register: at_check0
|
||||
|
||||
- name: verify at command is missing
|
||||
shell: which at
|
||||
register: at_check1
|
||||
failed_when: at_check1.rc == 0
|
||||
|
||||
- name: reinstall at package
|
||||
package:
|
||||
name: at
|
||||
state: present
|
||||
register: at_install0
|
||||
- debug: var=at_install0
|
||||
- name: validate results
|
||||
assert:
|
||||
that:
|
||||
- 'at_install0.changed is defined'
|
||||
- 'at_install0.changed'
|
||||
|
||||
- name: verify at command is installed
|
||||
shell: which at
|
||||
|
||||
when: ansible_distribution in package_distros
|
1
test/integration/targets/raw/aliases
Normal file
1
test/integration/targets/raw/aliases
Normal file
|
@ -0,0 +1 @@
|
|||
posix/ci/group1
|
2
test/integration/targets/raw/meta/main.yml
Normal file
2
test/integration/targets/raw/meta/main.yml
Normal file
|
@ -0,0 +1,2 @@
|
|||
dependencies:
|
||||
- prepare_tests
|
83
test/integration/targets/raw/tasks/main.yml
Normal file
83
test/integration/targets/raw/tasks/main.yml
Normal file
|
@ -0,0 +1,83 @@
|
|||
# Test code for the raw module.
|
||||
# (c) 2017, James Tanner <tanner.jc@gmail.com>
|
||||
|
||||
# This file is part of Ansible
|
||||
#
|
||||
# Ansible is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# Ansible is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
- set_fact: output_dir_test={{output_dir}}/test_command_raw
|
||||
|
||||
- name: make sure our testing sub-directory does not exist
|
||||
file: path="{{ output_dir_test }}" state=absent
|
||||
|
||||
- name: create our testing sub-directory
|
||||
file: path="{{ output_dir_test }}" state=directory
|
||||
|
||||
##
|
||||
## raw
|
||||
##
|
||||
|
||||
- name: touch a file
|
||||
raw: "touch {{output_dir_test | expanduser}}/test.txt"
|
||||
register: raw_result0
|
||||
- debug: var=raw_result0
|
||||
- stat:
|
||||
path: "{{output_dir_test | expanduser}}/test.txt"
|
||||
register: raw_result0_stat
|
||||
- debug: var=raw_result0_stat
|
||||
- name: ensure proper results
|
||||
assert:
|
||||
that:
|
||||
- 'raw_result0.changed is defined'
|
||||
- 'raw_result0.rc is defined'
|
||||
- 'raw_result0.stderr is defined'
|
||||
- 'raw_result0.stdout is defined'
|
||||
- 'raw_result0.stdout_lines is defined'
|
||||
- 'raw_result0.rc == 0'
|
||||
- 'raw_result0_stat.stat.size == 0'
|
||||
|
||||
- name: run a piped command
|
||||
raw: "echo 'foo,bar,baz' | cut -d\\, -f2 | tr 'b' 'c'"
|
||||
register: raw_result1
|
||||
- debug: var=raw_result1
|
||||
- name: ensure proper results
|
||||
assert:
|
||||
that:
|
||||
- 'raw_result1.changed is defined'
|
||||
- 'raw_result1.rc is defined'
|
||||
- 'raw_result1.stderr is defined'
|
||||
- 'raw_result1.stdout is defined'
|
||||
- 'raw_result1.stdout_lines is defined'
|
||||
- 'raw_result1.rc == 0'
|
||||
- 'raw_result1.stdout_lines == ["car"]'
|
||||
|
||||
- name: get the path to bash
|
||||
shell: which bash
|
||||
register: bash_path
|
||||
- name: run exmample non-posix command with bash
|
||||
raw: "echo 'foobar' > {{output_dir_test | expanduser}}/test.txt ; cat < {{output_dir_test | expanduser}}/test.txt"
|
||||
args:
|
||||
executable: "{{ bash_path.stdout }}"
|
||||
register: raw_result2
|
||||
- debug: var=raw_result2
|
||||
- name: ensure proper results
|
||||
assert:
|
||||
that:
|
||||
- 'raw_result2.changed is defined'
|
||||
- 'raw_result2.rc is defined'
|
||||
- 'raw_result2.stderr is defined'
|
||||
- 'raw_result2.stdout is defined'
|
||||
- 'raw_result2.stdout_lines is defined'
|
||||
- 'raw_result2.rc == 0'
|
||||
- 'raw_result2.stdout_lines == ["foobar"]'
|
3
test/integration/targets/sysctl/aliases
Normal file
3
test/integration/targets/sysctl/aliases
Normal file
|
@ -0,0 +1,3 @@
|
|||
posix/ci/group1
|
||||
skip/freebsd
|
||||
skip/osx
|
11
test/integration/targets/sysctl/files/sysctl.conf
Normal file
11
test/integration/targets/sysctl/files/sysctl.conf
Normal file
|
@ -0,0 +1,11 @@
|
|||
# sysctl settings are defined through files in
|
||||
# /usr/lib/sysctl.d/, /run/sysctl.d/, and /etc/sysctl.d/.
|
||||
#
|
||||
# Vendors settings live in /usr/lib/sysctl.d/.
|
||||
# To override a whole file, create a new file with the same in
|
||||
# /etc/sysctl.d/ and put new settings there. To override
|
||||
# only specific settings, add a file with a lexically later
|
||||
# name in /etc/sysctl.d/ and put new settings there.
|
||||
#
|
||||
# For more information, see sysctl.conf(5) and sysctl.d(5).
|
||||
vm.swappiness=1
|
2
test/integration/targets/sysctl/meta/main.yml
Normal file
2
test/integration/targets/sysctl/meta/main.yml
Normal file
|
@ -0,0 +1,2 @@
|
|||
dependencies:
|
||||
- prepare_tests
|
91
test/integration/targets/sysctl/tasks/main.yml
Normal file
91
test/integration/targets/sysctl/tasks/main.yml
Normal file
|
@ -0,0 +1,91 @@
|
|||
# Test code for the sysctl module.
|
||||
# (c) 2017, James Tanner <tanner.jc@gmail.com>
|
||||
|
||||
# This file is part of Ansible
|
||||
#
|
||||
# Ansible is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# Ansible is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
- set_fact: output_dir_test={{output_dir}}/test_sysctl
|
||||
|
||||
- name: make sure our testing sub-directory does not exist
|
||||
file: path="{{ output_dir_test }}" state=absent
|
||||
|
||||
- name: create our testing sub-directory
|
||||
file: path="{{ output_dir_test }}" state=directory
|
||||
|
||||
##
|
||||
## sysctl - file manipulation
|
||||
##
|
||||
|
||||
- name: copy the example conf to the test dir
|
||||
copy:
|
||||
src: sysctl.conf
|
||||
dest: "{{ output_dir_test }}"
|
||||
|
||||
- name: Set vm.swappiness to 5
|
||||
sysctl:
|
||||
name: vm.swappiness
|
||||
value: 5
|
||||
state: present
|
||||
reload: False
|
||||
sysctl_file: "{{ output_dir_test }}/sysctl.conf"
|
||||
register: sysctl_test0
|
||||
- debug: var=sysctl_test0
|
||||
|
||||
- name: get file content
|
||||
shell: "cat {{ output_dir_test }}/sysctl.conf | egrep -v ^\\#"
|
||||
register: sysctl_content0
|
||||
- debug: var=sysctl_content0
|
||||
|
||||
- name: Set vm.swappiness to 5 again
|
||||
sysctl:
|
||||
name: vm.swappiness
|
||||
value: 5
|
||||
state: present
|
||||
reload: False
|
||||
sysctl_file: "{{ output_dir_test }}/sysctl.conf"
|
||||
register: sysctl_test1
|
||||
|
||||
- name: validate results
|
||||
assert:
|
||||
that:
|
||||
- 'sysctl_test0.changed is defined'
|
||||
- 'sysctl_test1.changed is defined'
|
||||
- 'sysctl_test0.changed'
|
||||
- 'not sysctl_test1.changed'
|
||||
- 'sysctl_content0.stdout_lines == ["vm.swappiness=5"]'
|
||||
|
||||
##
|
||||
## sysctl - sysctl_set
|
||||
##
|
||||
|
||||
- name: set net.ipv4.ip_forward
|
||||
sysctl:
|
||||
name: net.ipv4.ip_forward
|
||||
value: 1
|
||||
sysctl_set: yes
|
||||
reload: False
|
||||
register: sysctl_test2
|
||||
- debug: var=sysctl_test2
|
||||
|
||||
- name: check with sysctl command
|
||||
shell: sysctl net.ipv4.ip_forward
|
||||
register: sysctl_check2
|
||||
|
||||
- name: validate results for test 2
|
||||
assert:
|
||||
that:
|
||||
- 'sysctl_test2.changed is defined'
|
||||
- 'sysctl_test2.changed'
|
||||
- 'sysctl_check2.stdout_lines == ["net.ipv4.ip_forward = 1"]'
|
1
test/integration/targets/systemd/aliases
Normal file
1
test/integration/targets/systemd/aliases
Normal file
|
@ -0,0 +1 @@
|
|||
posix/ci/group1
|
2
test/integration/targets/systemd/meta/main.yml
Normal file
2
test/integration/targets/systemd/meta/main.yml
Normal file
|
@ -0,0 +1,2 @@
|
|||
dependencies:
|
||||
- prepare_tests
|
50
test/integration/targets/systemd/tasks/main.yml
Normal file
50
test/integration/targets/systemd/tasks/main.yml
Normal file
|
@ -0,0 +1,50 @@
|
|||
# Test code for the systemd module.
|
||||
# (c) 2017, James Tanner <tanner.jc@gmail.com>
|
||||
|
||||
# This file is part of Ansible
|
||||
#
|
||||
# Ansible is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# Ansible is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
##
|
||||
## systemctl
|
||||
##
|
||||
|
||||
- name: check for systemctl command
|
||||
shell: which systemctl
|
||||
failed_when: False
|
||||
register: systemctl_check
|
||||
|
||||
- block:
|
||||
- name: get a list of running services
|
||||
shell: systemctl | fgrep 'running' | awk '{print $1}' | sed 's/\.service//g' | fgrep -v '.' | egrep ^[a-z]
|
||||
register: running_names
|
||||
- debug: var=running_names
|
||||
|
||||
- name: check running state
|
||||
systemd:
|
||||
name: "{{ running_names.stdout_lines|random }}"
|
||||
state: started
|
||||
register: systemd_test0
|
||||
- debug: var=systemd_test0
|
||||
- name: validate results for test0
|
||||
assert:
|
||||
that:
|
||||
- 'systemd_test0.changed is defined'
|
||||
- 'systemd_test0.name is defined'
|
||||
- 'systemd_test0.state is defined'
|
||||
- 'systemd_test0.status is defined'
|
||||
- 'not systemd_test0.changed'
|
||||
- 'systemd_test0.state == "started"'
|
||||
|
||||
when: 'systemctl_check.rc == 0'
|
1
test/integration/targets/user/aliases
Normal file
1
test/integration/targets/user/aliases
Normal file
|
@ -0,0 +1 @@
|
|||
posix/ci/group1
|
20
test/integration/targets/user/files/userlist.sh
Normal file
20
test/integration/targets/user/files/userlist.sh
Normal file
|
@ -0,0 +1,20 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
#- name: make a list of groups
|
||||
# shell: |
|
||||
# cat /etc/group | cut -d: -f1
|
||||
# register: group_names
|
||||
# when: 'ansible_distribution != "MacOSX"'
|
||||
|
||||
#- name: make a list of groups [mac]
|
||||
# shell: dscl localhost -list /Local/Default/Groups
|
||||
# register: group_names
|
||||
# when: 'ansible_distribution == "MacOSX"'
|
||||
|
||||
DISTRO="$*"
|
||||
|
||||
if [[ "$DISTRO" == "MacOSX" ]]; then
|
||||
dscl localhost -list /Local/Default/Users
|
||||
else
|
||||
egrep -v ^\# /etc/passwd | cut -d: -f1
|
||||
fi
|
2
test/integration/targets/user/meta/main.yml
Normal file
2
test/integration/targets/user/meta/main.yml
Normal file
|
@ -0,0 +1,2 @@
|
|||
dependencies:
|
||||
- prepare_tests
|
110
test/integration/targets/user/tasks/main.yml
Normal file
110
test/integration/targets/user/tasks/main.yml
Normal file
|
@ -0,0 +1,110 @@
|
|||
# Test code for the user module.
|
||||
# (c) 2017, James Tanner <tanner.jc@gmail.com>
|
||||
|
||||
# This file is part of Ansible
|
||||
#
|
||||
# Ansible is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# Ansible is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
- name: get the jinja2 version
|
||||
shell: python -c 'import jinja2; print(jinja2.__version__)'
|
||||
register: jinja2_version
|
||||
delegate_to: localhost
|
||||
- debug: var=jinja2_version
|
||||
|
||||
##
|
||||
## user add
|
||||
##
|
||||
#
|
||||
- name: remove the test user
|
||||
user:
|
||||
name: ansibulluser
|
||||
state: absent
|
||||
|
||||
- name: try to create a user
|
||||
user:
|
||||
name: ansibulluser
|
||||
state: present
|
||||
register: user_test0
|
||||
- debug: var=user_test0
|
||||
|
||||
- name: make a list of users
|
||||
script: userlist.sh "{{ ansible_distribution }}"
|
||||
register: user_names
|
||||
- debug: var=user_names
|
||||
|
||||
- name: validate results for testcase 0
|
||||
assert:
|
||||
that:
|
||||
- 'user_test0.changed is defined'
|
||||
- 'user_test0.changed'
|
||||
- '"ansibulluser" in user_names.stdout_lines'
|
||||
|
||||
##
|
||||
## user check
|
||||
##
|
||||
|
||||
- name: run existing user check tests
|
||||
user:
|
||||
name: "{{ user_names.stdout_lines|random }}"
|
||||
state: present
|
||||
createhome: no
|
||||
with_sequence: start=1 end=5
|
||||
register: user_test1
|
||||
- debug: var=user_test1
|
||||
|
||||
- name: validate results for testcase 1
|
||||
assert:
|
||||
that:
|
||||
- 'user_test1.results is defined'
|
||||
- 'user_test1.results|length == 5'
|
||||
|
||||
- name: validate changed results for testcase 1 (jinja >= 2.6)
|
||||
assert:
|
||||
that:
|
||||
- "user_test1.results|map(attribute='changed')|unique|list == [False]"
|
||||
- "user_test1.results|map(attribute='state')|unique|list == ['present']"
|
||||
when: "jinja2_version.stdout|version_compare('2.6', '>=')"
|
||||
|
||||
- name: validate changed results for testcase 1 (jinja >= 2.6)
|
||||
assert:
|
||||
that:
|
||||
- "not user_test1.results[0]['changed']"
|
||||
- "not user_test1.results[1]['changed']"
|
||||
- "not user_test1.results[2]['changed']"
|
||||
- "not user_test1.results[3]['changed']"
|
||||
- "not user_test1.results[4]['changed']"
|
||||
- "user_test1.results[0]['state'] == 'present'"
|
||||
- "user_test1.results[1]['state'] == 'present'"
|
||||
- "user_test1.results[2]['state'] == 'present'"
|
||||
- "user_test1.results[3]['state'] == 'present'"
|
||||
- "user_test1.results[4]['state'] == 'present'"
|
||||
when: "jinja2_version.stdout|version_compare('2.6', '<')"
|
||||
|
||||
##
|
||||
## user remove
|
||||
##
|
||||
|
||||
- name: try to delete the user
|
||||
user:
|
||||
name: ansibulluser
|
||||
state: absent
|
||||
register: user_test2
|
||||
- name: make a new list of users
|
||||
script: userlist.sh "{{ ansible_distribution }}"
|
||||
register: user_names2
|
||||
- debug: var=user_names2
|
||||
- name: validate results for testcase 2
|
||||
assert:
|
||||
that:
|
||||
- '"ansibulluser" not in user_names2.stdout_lines'
|
Loading…
Reference in a new issue