#!/usr/bin/env perl
our
$VERSION
=
'0.3'
;
sub
_args {
my
$args
= Getopt::Long::Configure(
qw/no_auto_abbrev no_ignore_case pass_through auto_version auto_help/
);
GetOptionsFromArray
shift
,
'h|help'
=> \
$ENV
{ANSIBLE_HELP},
'a|args=s'
=> \
$ENV
{ANSIBLE_ARGS},
'p|pack'
=> \
$ENV
{ANSIBLE_PACK},
'm|module_path=s'
=> \
$ENV
{ANSIBLE_MODULE},
'c|check'
=> \
$ENV
{ANSIBLE_CHECK_MODE};
Getopt::Long::Configure(
$args
);
}
BEGIN { _args([
@ARGV
]) };
exit
print
Mojolicious::Command->extract_usage()
if
$ENV
{ANSIBLE_HELP} || !
$ENV
{ANSIBLE_MODULE};
if
(
$ENV
{ANSIBLE_PACK}) {
my
$fp
=App::FatPacker->new;
my
@modules
=
split
/\r?\n/,
$fp
->trace(
args
=> [
$ENV
{ANSIBLE_MODULE}]);
push
@modules
,
'AnsibleModule.pm'
;
my
@packlists
=
$fp
->packlists_containing(\
@modules
);
my
$base
= catdir(cwd,
'fatlib'
);
$fp
->packlists_to_tree(
$base
, \
@packlists
);
my
$code
=
$fp
->fatpack_file(
$ENV
{ANSIBLE_MODULE});
$ENV
{ANSIBLE_MODULE}=
$ENV
{ANSIBLE_MODULE}.
'.packed'
;
spurt
$code
,
$ENV
{ANSIBLE_MODULE};
chmod
0755,
$ENV
{ANSIBLE_MODULE};
print
"Wrote $ENV{ANSIBLE_MODULE}\n"
;
exit
0;
}
$ENV
{ANSIBLE_ARGS} ||=
"{}"
;
my
$t
=Test::AnsibleModule->new;
my
$res
=
$t
->exec_module(
$ENV
{ANSIBLE_MODULE},decode_json(
$ENV
{ANSIBLE_ARGS}));
print
"Output from $ENV{ANSIBLE_MODULE}: "
. dumper(
$t
->last_response);
print
"Response code: $res\n"
;