Sparrowdo automation. Part 3. Installing system packages.
HI! I continue blogging about sparrowdo - a simple perl6 configuration management tool.
This is what we've learned so far:
Installing packages
Consider out latest example with installing CPAN packages:
$ cat sparrowfile
use v6;
use Sparrowdo;
task_run %(
task => 'install CGI',
plugin => 'cpan-package',
parameters => %( list => 'CGI' ),
);
What we are trying to do here is to install CGI CPAN module using cpan-package plugin. Here is little trick is hidden. A cpan-package implies you have a cpanm client pre-installed at your system. Let's see what will happen if it is not:
$ sparrowdo --ssh_port=2200 --host=127.0.0.1 --ssh_user=vagrant
running sparrow tasks on 127.0.0.1 ...
running task <install-CGI> plg <cpan-package>
parameters: {list => CGI}
/opt/sparrow/tmp/8417/opt/sparrow/plugins/public/cpan-package/story.t ..
# [/opt/sparrow/plugins/public/cpan-package/modules/cpanm]
# install CGI ...
# /opt/sparrow/plugins/public/cpan-package/modules/cpanm/story.bash: line 22: cpanm: command not found
not ok 1 - scenario succeeded
# Failed test 'scenario succeeded'
# at /usr/local/share/perl/5.20.2/Outthentic.pm line 193.
not ok 2 - output match 'install ok'
# [/opt/sparrow/plugins/public/cpan-package]
# cpan-package-done
ok 3 - output match 'cpan-package-done'
1..3
# Failed test 'output match 'install ok''
# at /usr/local/share/perl/5.20.2/Outthentic.pm line 239.
# Looks like you failed 2 tests of 3.
Dubious, test returned 2 (wstat 512, 0x200)
Failed 2/3 subtests
Test Summary Report
-------------------
/opt/sparrow/tmp/8417/opt/sparrow/plugins/public/cpan-package/story.t (Wstat: 512 Tests: 3 Failed: 2)
Failed tests: 1-2
Non-zero exit status: 2
Files=1, Tests=3, 0 wallclock secs ( 0.02 usr 0.00 sys + 0.10 cusr 0.00 csys = 0.12 CPU)
Result: FAIL
The spawned process exited unsuccessfully (exit code: 1)
in block <unit> at /home/melezhik/.rakudobrew/moar-nom/install/share/perl6/site/resources/CDEEEB90951FEDF24FB0EE4EFB79E7A6061B289C line 3
Upps, obviously we see the reason of the failure here:
cpanm: command not found
So, we need to install cpanm client to our system first to make it working cpan-package plugin. One day I probably add this dependency into cpan-package itself , but for now we could use a package-generic plugin to install any system packages.
Luckily we have cpanminus ubuntu package to install cpanm client on our ubuntu box:
$ cat sparrowfile
use v6;
use Sparrowdo;
task_run %(
task => 'install cpanm client',
plugin => 'package-generic',
parameters => %( list => 'cpanminus' )
);
task_run %(
task => 'install CGI',
plugin => 'cpan-package',
parameters => %(
list => 'CGI',
),
);
Let's give it a run ...
$ sparrowdo --ssh_port=2200 --host=127.0.0.1 --ssh_user=vagrant
running sparrow tasks on 127.0.0.1 ...
running task <install cpanm client> plg <package-generic>
parameters: {list => cpanminus}
/opt/sparrow/tmp/8792/opt/sparrow/plugins/public/package-generic/story.t ..
# [/opt/sparrow/plugins/public/package-generic/modules/apt-get]
# trying to install cpanminus ...
# installer - apt-get
# Package: cpanminus
# Version: 1.7014-1
# Status: install ok installed
ok 1 - output match 'Status: install ok installed'
# [/opt/sparrow/plugins/public/package-generic]
# package-generic-done
ok 2 - output match 'package-generic-done'
1..2
ok
All tests successful.
Files=1, Tests=2, 2 wallclock secs ( 0.02 usr 0.00 sys + 0.67 cusr 0.20 csys = 0.89 CPU)
Result: PASS
running task <install-CGI> plg <cpan-package>
parameters: {list => CGI}
/opt/sparrow/tmp/10304/opt/sparrow/plugins/public/cpan-package/story.t ..
# [/opt/sparrow/plugins/public/cpan-package/modules/cpanm]
# install CGI ...
# CGI is up to date. (4.31)
# install ok
ok 1 - output match 'install ok'
# [/opt/sparrow/plugins/public/cpan-package]
# cpan-package-done
ok 2 - output match 'cpan-package-done'
1..2
ok
All tests successful.
Files=1, Tests=2, 0 wallclock secs ( 0.01 usr 0.00 sys + 0.18 cusr 0.05 csys = 0.24 CPU)
Result: PASS
Ok, now it succeeded!
A few comments on package-generic usage:
A limited set of platforms are supported - CentOS, Ubuntu, Debian. At least this works for me. If you need more - let me know or make a pull request!
No "platform-sensitive" packages naming conventions available like in other more mature systems ( chef, ansible ).
One day I would like something like that into sparrowdo API:
task_run %(
task => 'install apache webserver',
plugin => 'package-generic',
parameters_for_platform => %(
ubuntu => %( list => 'apache2' ),
debian => %( list => 'apache2' ),
cetnos => %( list => 'httpd' ),
default => %( list => 'apache2' ),
),
);
- And finally. No specific version installation is supported. The plugin is quite simple. But it works for me. If you consider more complicated cases - let me know! :)
Cleaning up old packages
In case you have Ubuntu, Debian boxes a latest version of package-generic plugin make it possible to autoremove old, useless stuff:
task_run %(
task => 'remove old packages',
plugin => 'package-generic',
parameters => %( action => 'autoremove' )
);
That is it. Approaching to the end ... :)
All the best. And see you soon. I have not thought about next topic too much, but probably I will be talking about managing users and groups with the help of sparrowdo ...
Leave a comment