diff options
author | Lars Wirzenius <liw@liw.fi> | 2017-06-04 13:17:21 +0300 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2017-06-04 13:48:28 +0300 |
commit | 2414fae798b910fb2800bd0456acbeaa5f09d584 (patch) | |
tree | 9a5e4f428137f80121c6b2074d6a6d17287a43f9 | |
parent | d2a5b0d29113ccb53f47608326a5c219ec4f2aad (diff) | |
download | vmdb2-2414fae798b910fb2800bd0456acbeaa5f09d584.tar.gz |
Add ansible plugin
-rw-r--r-- | vmdb/plugins/ansible_plugin.py | 65 | ||||
-rw-r--r-- | without-tests | 1 |
2 files changed, 66 insertions, 0 deletions
diff --git a/vmdb/plugins/ansible_plugin.py b/vmdb/plugins/ansible_plugin.py new file mode 100644 index 0000000..83a989e --- /dev/null +++ b/vmdb/plugins/ansible_plugin.py @@ -0,0 +1,65 @@ +# Copyright 2017 Lars Wirzenius +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# +# =*= License: GPL-3+ =*= + + + +import logging +import os +import tempfile + +import cliapp + +import vmdb + + +class AnsiblePlugin(cliapp.Plugin): + + def enable(self): + self.app.step_runners.add(AnsibleStepRunner()) + + +class AnsibleStepRunner(vmdb.StepRunnerInterface): + + def get_required_keys(self): + return ['ansible', 'playbook'] + + def run(self, step, settings, state): + fstag = step['ansible'] + playbook = step['playbook'] + mount_point = state.mounts[fstag] + + vmdb.progress( + 'Running ansible playbook {} on filesystem at {} ({})'.format( + playbook, mount_point, fstag)) + + state.ansible_inventory = self.create_inventory(mount_point) + vmdb.progress( + 'Created {} for Ansible inventory'.format(state.ansible_inventory)) + vmdb.runcmd( + ['ansible-playbook', '-c', 'chroot', + '-i', state.ansible_inventory, playbook]) + + def teardown(self, step, settings, state): + if hasattr(state, 'ansible_inventory'): + vmdb.progress('Removing {}'.format(state.ansible_inventory)) + os.remove(state.ansible_inventory) + + def create_inventory(self, chroot): + fd, filename = tempfile.mkstemp() + os.write(fd, '[image]\n{}\n'.format(chroot)) + os.close(fd) + return filename diff --git a/without-tests b/without-tests index c950117..203875e 100644 --- a/without-tests +++ b/without-tests @@ -4,6 +4,7 @@ vmdb/app.py vmdb/runcmd.py vmdb/state.py vmdb/version.py +vmdb/plugins/ansible_plugin.py vmdb/plugins/apt_plugin.py vmdb/plugins/chroot_plugin.py vmdb/plugins/debootstrap_plugin.py |