mirror of https://github.com/ansible/ansible.git
module_utils fixes in collections (#55118)
* module_utils fixes in collections * fixed Windows module_utils in collections * fixed more Python module_utils cases (from X import module) * "medium style" Ansiballz modules now work properly with collections (ie, non-replacer but also not using basic.py) * added more tests * split Windows/POSIX exec * sanitypull/55130/head
parent
9bd060292e
commit
1dc8436ed9
@ -1,2 +1,5 @@
|
||||
posix
|
||||
shippable/posix/group4
|
||||
shippable/windows/group2
|
||||
skip/python2.6
|
||||
windows
|
||||
|
@ -0,0 +1,12 @@
|
||||
using System;
|
||||
|
||||
namespace AnsibleCollections.testns.testcoll.AnotherCSMU
|
||||
{
|
||||
public class AnotherThing
|
||||
{
|
||||
public static string CallMe()
|
||||
{
|
||||
return "Hello from nested user-collection-hosted AnotherCSMU";
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
using System;
|
||||
|
||||
using AnsibleCollections.testns.testcoll.AnotherCSMU;
|
||||
|
||||
namespace AnsibleCollections.testns.testcoll.MyCSMU
|
||||
{
|
||||
public class CustomThing
|
||||
{
|
||||
public static string HelloWorld()
|
||||
{
|
||||
string res = AnotherThing.CallMe();
|
||||
return String.Format("Hello from user_mu collection-hosted MyCSMU, also {0}", res);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
Function CallMe-FromUserPSMU {
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Test function
|
||||
#>
|
||||
return "from user_mu"
|
||||
}
|
||||
|
||||
Export-ModuleMember -Function CallMe-FromUserPSMU
|
@ -0,0 +1,2 @@
|
||||
def thingtocall():
|
||||
return "thingtocall in subpkg.submod"
|
@ -0,0 +1,2 @@
|
||||
def thingtocall():
|
||||
return "thingtocall in subpkg_with_init"
|
@ -0,0 +1,22 @@
|
||||
#!powershell
|
||||
|
||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
|
||||
#AnsibleRequires -CSharpUtil Ansible.Basic
|
||||
|
||||
$spec = @{
|
||||
options = @{
|
||||
data = @{ type = "str"; default = "pong" }
|
||||
}
|
||||
supports_check_mode = $true
|
||||
}
|
||||
$module = [Ansible.Basic.AnsibleModule]::Create($args, $spec)
|
||||
$data = $module.Params.data
|
||||
|
||||
if ($data -eq "crash") {
|
||||
throw "boom"
|
||||
}
|
||||
|
||||
$module.Result.ping = $data
|
||||
$module.Result.source = "user"
|
||||
$module.ExitJson()
|
@ -0,0 +1,9 @@
|
||||
#!powershell
|
||||
|
||||
$res = @{
|
||||
changed = $false
|
||||
source = "user"
|
||||
msg = "hi from selfcontained.ps1"
|
||||
}
|
||||
|
||||
ConvertTo-Json $res
|
@ -0,0 +1 @@
|
||||
# docs for Windows module would go here; just ensure we don't accidentally load this instead of the .ps1
|
@ -0,0 +1,23 @@
|
||||
#!powershell
|
||||
|
||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
|
||||
#AnsibleRequires -CSharpUtil Ansible.Basic
|
||||
#AnsibleRequires -CSharpUtil AnsibleCollections.testns.testcoll.MyCSMU
|
||||
|
||||
$spec = @{
|
||||
options = @{
|
||||
data = @{ type = "str"; default = "called from $([AnsibleCollections.testns.testcoll.MyCSMU.CustomThing]::HelloWorld())" }
|
||||
}
|
||||
supports_check_mode = $true
|
||||
}
|
||||
$module = [Ansible.Basic.AnsibleModule]::Create($args, $spec)
|
||||
$data = $module.Params.data
|
||||
|
||||
if ($data -eq "crash") {
|
||||
throw "boom"
|
||||
}
|
||||
|
||||
$module.Result.ping = $data
|
||||
$module.Result.source = "user"
|
||||
$module.ExitJson()
|
@ -0,0 +1,23 @@
|
||||
#!powershell
|
||||
|
||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
|
||||
#AnsibleRequires -CSharpUtil Ansible.Basic
|
||||
#AnsibleRequires -Powershell AnsibleCollections.testns.testcoll.MyPSMU
|
||||
|
||||
$spec = @{
|
||||
options = @{
|
||||
data = @{ type = "str"; default = "called from $(CallMe-FromUserPSMU)" }
|
||||
}
|
||||
supports_check_mode = $true
|
||||
}
|
||||
$module = [Ansible.Basic.AnsibleModule]::Create($args, $spec)
|
||||
$data = $module.Params.data
|
||||
|
||||
if ($data -eq "crash") {
|
||||
throw "boom"
|
||||
}
|
||||
|
||||
$module.Result.ping = $data
|
||||
$module.Result.source = "user"
|
||||
$module.ExitJson()
|
@ -0,0 +1,6 @@
|
||||
- testns.testcoll.plugin_lookup:
|
||||
register: included_plugin_lookup_out
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- included_plugin_lookup_out.collection_list == ['bogus.bogus', 'ansible.legacy']
|
@ -0,0 +1,20 @@
|
||||
- hosts: windows
|
||||
tasks:
|
||||
- testns.testcoll.win_selfcontained:
|
||||
register: selfcontained_out
|
||||
|
||||
- testns.testcoll.win_csbasic_only:
|
||||
register: csbasic_only_out
|
||||
|
||||
- testns.testcoll.win_uses_coll_psmu:
|
||||
register: uses_coll_psmu
|
||||
|
||||
- testns.testcoll.win_uses_coll_csmu:
|
||||
register: uses_coll_csmu
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- selfcontained_out.source == 'user'
|
||||
- csbasic_only_out.source == 'user'
|
||||
- uses_coll_psmu.source == 'user' and 'user_mu' in uses_coll_psmu.ping
|
||||
- uses_coll_csmu.source == 'user' and 'user_mu' in uses_coll_csmu.ping
|
Loading…
Reference in New Issue