enhance ansible for non ssl connection
This commit is contained in:
parent
1a5dbae60c
commit
3bd96e6a43
|
@ -40,7 +40,7 @@ sub new {
|
|||
|
||||
if (!defined($options{noptions})) {
|
||||
$options{options}->add_options(arguments => {
|
||||
'host:s' => { name => 'host' },
|
||||
'hostname:s' => { name => 'hostname' },
|
||||
'username:s' => { name => 'username' },
|
||||
'password:s' => { name => 'password' },
|
||||
'timeout:s' => { name => 'timeout', default => 50 },
|
||||
|
@ -48,13 +48,14 @@ sub new {
|
|||
'command:s' => { name => 'command', default => 'tower-cli' },
|
||||
'command-path:s' => { name => 'command_path' },
|
||||
'command-options:s' => { name => 'command_options', default => '' },
|
||||
'nossl' => { name => 'nossl' },
|
||||
'proxyurl:s' => { name => 'proxyurl' }
|
||||
});
|
||||
}
|
||||
$options{options}->add_help(package => __PACKAGE__, sections => 'TOWERCLI OPTIONS', once => 1);
|
||||
|
||||
$self->{output} = $options{output};
|
||||
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
|
@ -74,9 +75,15 @@ sub check_options {
|
|||
$ENV{HTTPS_PROXY} = $self->{option_results}->{proxyurl};
|
||||
}
|
||||
|
||||
$self->{host} = (defined($self->{option_results}->{host})) ? $self->{option_results}->{host} : undef;
|
||||
$self->{username} = (defined($self->{option_results}->{username})) ? $self->{option_results}->{username} : undef;
|
||||
$self->{password} = (defined($self->{option_results}->{password})) ? $self->{option_results}->{password} : undef;
|
||||
$self->{hostname} = (defined($self->{option_results}->{hostname})) && $self->{option_results}->{hostname} ne '' ? $self->{option_results}->{hostname} : undef;
|
||||
$self->{username} = (defined($self->{option_results}->{username})) && $self->{option_results}->{username} ne '' ? $self->{option_results}->{username} : undef;
|
||||
$self->{password} = (defined($self->{option_results}->{password})) && $self->{option_results}->{password} ne '' ? $self->{option_results}->{password} : undef;
|
||||
|
||||
if (defined($self->{option_results}->{nossl})) {
|
||||
$ENV{TOWER_VERIFY_SSL} = 'no';
|
||||
$self->{hostname} = 'http://' . $self->{hostname} if (defined($self->{hostname}));
|
||||
$ENV{HTTPS_PROXY} = $self->{option_results}->{proxyurl};
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -85,14 +92,15 @@ sub execute {
|
|||
my ($self, %options) = @_;
|
||||
|
||||
$self->{output}->output_add(long_msg => "Command line: '" . $self->{option_results}->{command} . " " . $options{cmd_options} . "'", debug => 1);
|
||||
|
||||
|
||||
my ($response) = centreon::plugins::misc::execute(
|
||||
output => $self->{output},
|
||||
options => $self->{option_results},
|
||||
sudo => $self->{option_results}->{sudo},
|
||||
command => $self->{option_results}->{command},
|
||||
command_path => $self->{option_results}->{command_path},
|
||||
command_options => $options{cmd_options});
|
||||
command_options => $options{cmd_options}
|
||||
);
|
||||
|
||||
my $raw_results;
|
||||
|
||||
|
@ -112,11 +120,11 @@ sub tower_list_hosts_set_cmd {
|
|||
my ($self, %options) = @_;
|
||||
|
||||
return if (defined($self->{option_results}->{command_options}) && $self->{option_results}->{command_options} ne '');
|
||||
|
||||
|
||||
my $cmd_options = "host list --insecure --all-pages --format json";
|
||||
$cmd_options .= " --tower-host '$self->{host}'" if (defined($self->{host}) && $self->{host} ne '');
|
||||
$cmd_options .= " --tower-username '$self->{username}'" if (defined($self->{username}) && $self->{username} ne '');
|
||||
$cmd_options .= " --tower-password '$self->{password}'" if (defined($self->{password}) && $self->{password} ne '');
|
||||
$cmd_options .= " --tower-host '$self->{hostname}'" if (defined($self->{hostname}));
|
||||
$cmd_options .= " --tower-username '$self->{username}'" if (defined($self->{username}));
|
||||
$cmd_options .= " --tower-password '$self->{password}'" if (defined($self->{password}));
|
||||
$cmd_options .= " --group '$options{group}'" if (defined($options{group}) && $options{group} ne '');
|
||||
$cmd_options .= " --inventory '$options{inventory}'" if (defined($options{inventory}) && $options{inventory} ne '');
|
||||
|
||||
|
@ -137,10 +145,10 @@ sub tower_list_inventories_set_cmd {
|
|||
|
||||
return if (defined($self->{option_results}->{command_options}) && $self->{option_results}->{command_options} ne '');
|
||||
|
||||
my $cmd_options = "inventory list --insecure --all-pages --format json";
|
||||
$cmd_options .= " --tower-host '$self->{host}'" if (defined($self->{host}) && $self->{host} ne '');
|
||||
$cmd_options .= " --tower-username '$self->{username}'" if (defined($self->{username}) && $self->{username} ne '');
|
||||
$cmd_options .= " --tower-password '$self->{password}'" if (defined($self->{password}) && $self->{password} ne '');
|
||||
my $cmd_options = 'inventory list --insecure --all-pages --format json';
|
||||
$cmd_options .= " --tower-host '$self->{hostname}'" if (defined($self->{hostname}));
|
||||
$cmd_options .= " --tower-username '$self->{username}'" if (defined($self->{username}));
|
||||
$cmd_options .= " --tower-password '$self->{password}'" if (defined($self->{password}));
|
||||
|
||||
return $cmd_options;
|
||||
}
|
||||
|
@ -160,9 +168,9 @@ sub tower_list_projects_set_cmd {
|
|||
return if (defined($self->{option_results}->{command_options}) && $self->{option_results}->{command_options} ne '');
|
||||
|
||||
my $cmd_options = "project list --insecure --all-pages --format json";
|
||||
$cmd_options .= " --tower-host '$self->{host}'" if (defined($self->{host}) && $self->{host} ne '');
|
||||
$cmd_options .= " --tower-username '$self->{username}'" if (defined($self->{username}) && $self->{username} ne '');
|
||||
$cmd_options .= " --tower-password '$self->{password}'" if (defined($self->{password}) && $self->{password} ne '');
|
||||
$cmd_options .= " --tower-host '$self->{hostname}'" if (defined($self->{hostname}));
|
||||
$cmd_options .= " --tower-username '$self->{username}'" if (defined($self->{username}));
|
||||
$cmd_options .= " --tower-password '$self->{password}'" if (defined($self->{password}));
|
||||
|
||||
return $cmd_options;
|
||||
}
|
||||
|
@ -192,9 +200,9 @@ To install the Tower CLI : https://docs.ansible.com/ansible-tower/latest/html/to
|
|||
|
||||
=over 8
|
||||
|
||||
=item B<--host>
|
||||
=item B<--hostname>
|
||||
|
||||
Ansible Tower host (Default uses setting in 'tower config').
|
||||
Ansible Tower hostname (Default uses setting in 'tower config').
|
||||
|
||||
=item B<--username>
|
||||
|
||||
|
@ -204,6 +212,10 @@ Ansible Tower username (Default uses setting in 'tower config').
|
|||
|
||||
Ansible Tower password (Default uses setting in 'tower config').
|
||||
|
||||
=item B<--nossl>
|
||||
|
||||
Use http connection.
|
||||
|
||||
=item B<--timeout>
|
||||
|
||||
Set timeout in seconds (Default: 50).
|
||||
|
|
|
@ -34,7 +34,7 @@ sub new {
|
|||
$options{options}->add_options(arguments => {
|
||||
'group' => { name => 'group' },
|
||||
'inventory' => { name => 'inventory' },
|
||||
'prettify' => { name => 'prettify' },
|
||||
'prettify' => { name => 'prettify' }
|
||||
});
|
||||
|
||||
return $self;
|
||||
|
|
Loading…
Reference in New Issue