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

let aii generate ansible playbook for supported components #331

Draft
wants to merge 28 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
f62ee82
core: Shellfe: cleanup
stdweird Apr 26, 2018
91c9c62
Shellfe: set active config before running the plugin method
stdweird Sep 21, 2016
963ac1f
ks: ksuserhooks: set active config before running the hook method
stdweird Sep 22, 2016
f1f22a1
aii-ks: fix some more regex tests after new nmc-lib-blockdevices
stdweird Aug 7, 2020
e685e9c
aii-ks: factor out proxy url modification
stdweird Nov 5, 2019
57279c4
aii-ks: factor out repository proxy and baseurl modification
stdweird Nov 5, 2019
7fa0409
aii-ks: generate the kickstart repo command from the SPMA repository …
stdweird Nov 6, 2019
111240b
aii-ks: do not install kernel debug rpms in post
stdweird Nov 18, 2019
9b486e1
aii-pxelinux: fix panlint line too long in schema
stdweird Nov 21, 2019
db9578a
aii-ks: switch to globs for repository selection and some more code c…
stdweird Aug 7, 2020
1f0788f
aii-ks: allow finegrained enable/disable/ignore control when generati…
stdweird Aug 7, 2020
669c13e
aii-ks: generalise the glob pattern used by repo selection and also e…
stdweird Aug 14, 2020
b1b6c25
aii-pxelinux: fix bug when calling _kernel_params with correct varian…
stdweird Aug 14, 2020
2da99b8
aii-pxelinux: add globbing to the pxelinux initrd and kernel paths
stdweird Aug 14, 2020
3928f1c
aii-ks: handle disabled/ignored packages in post too
stdweird Aug 18, 2020
eb9c80a
aii-ks: add boolean to control installation of (exact) kernel package…
stdweird Aug 18, 2020
a5733f0
aii-ks: only root access to /tmp yum and log files
stdweird Aug 19, 2020
e0bf6b6
aii-pxelinux: Fix UEFI boot over http
stdweird Mar 16, 2021
b31044b
pxelinux: support hostname lookup for EFI
stdweird Apr 14, 2021
bd1d314
aii-core: support changing plugin modulename
stdweird Jul 1, 2021
585f48c
aii-ks: add kickstart_post_script plugin module to generate the post …
stdweird Jul 1, 2021
f5e7727
aii-ks: ks_post_script: generate the repos first
stdweird Aug 5, 2021
056468b
aii-ks: for kickstart as script, run ks-post-install in "post"
stdweird Sep 22, 2021
749d956
aii-ks: fix permission of ks-post-reboot script
stdweird Sep 24, 2021
fca85b0
aii-core: add ansible command
stdweird Oct 20, 2021
90c968f
aii-core: add ansible playbook, role and task module
stdweird Oct 20, 2021
539923d
aii-core: add more ansible tests
stdweird Oct 21, 2021
ace5b1b
aii-core: ansible task: support passing data on task creation
stdweird Oct 22, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 83 additions & 0 deletions aii-core/src/main/perl/Playbook.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#${PMpre} AII::Playbook${PMpost}

use LC::Exception qw (SUCCESS);
use parent qw(CAF::Object);
use CAF::TextRender;
use CAF::Path;

use AII::Role;

# hosts: playbook hosts
sub _initialize
{
my ($self, $hosts, %opts) = @_;

%opts = () if !%opts;

$self->{log} = $opts{log} if $opts{log};

$self->{data} = {
hosts => $hosts
};
$self->{roles} = [];

return SUCCESS;
}

sub add_role
{
my ($self, $name) = @_;
my $role = AII::Role->new($name, log => $self);
push @{$self->{roles}}, $role;
return $role;
}


# Generate hashref to render into yaml
sub make_data {
my $self = shift;

# make copy of basic data
my $data = {%{$self->{data}}};

# add roles
$data->{roles} = [map {$_->{name}} @{$self->{roles}}];

return $data;
}

# Generate playbook and roles
# root: base working dir
sub write
{
my ($self, $root) = @_;

# Make roles subdir in root
my $cafpath = CAF::Path::mkcafpath(log => $self);
$cafpath->directory("$root/roles");

# Generate all roles and playbook data
my $files = {
main => $self->make_data()
};

foreach my $role (@{$self->{roles}}) {
$files->{"roles/$role->{name}"} = $role->make_data();
}

# Write
foreach my $filename (sort keys %$files) {
my $trd = CAF::TextRender->new(
'yamlmulti',
{'host' => [$files->{$filename}]}, # use yamlmulti to bypass arrayref issue
log => $self,
);
my $fh = $trd->filewriter(
"$root/$filename.yml",
log => $self,
);
$fh->close();
};
}

1;
46 changes: 46 additions & 0 deletions aii-core/src/main/perl/Role.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#${PMpre} AII::Role${PMpost}

use LC::Exception qw (SUCCESS);
use parent qw(CAF::Object);

use AII::Task;

# name: name of role
sub _initialize
{
my ($self, $name, %opts) = @_;

%opts = () if !%opts;

$self->{log} = $opts{log} if $opts{log};

$self->{name} = $name;
$self->{data} = {
};
$self->{tasks} = [];

return SUCCESS;
}

sub add_task
{
my ($self, $name, $data) = @_;
my $task = AII::Task->new($name, $data, log => $self);
push @{$self->{tasks}}, $task;
return $task;
}

# Generate hashref to render into yaml
sub make_data {
my $self = shift;

# make copy of basic data
my $data = {%{$self->{data}}};

# add tasks
$data->{tasks} = [map {$_->make_data()} @{$self->{tasks}}];

return $data;
}

1;
Loading