Skip to content

Commit 610b3cc

Browse files
committed
Merge pull request aminator-plugins#10 from Answers4AWS/master
Refactoring for new base plugin
2 parents 61b32d2 + 8e8c0ae commit 610b3cc

File tree

1 file changed

+9
-36
lines changed

1 file changed

+9
-36
lines changed

aminatorplugins/provisioner/ansible.py

Lines changed: 9 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@
2525
import os
2626
import shutil
2727

28+
from aminator.plugins.provisioner.base import BaseProvisionerPlugin
2829
from aminator.config import conf_action
29-
from aminator.plugins.provisioner.linux import BaseProvisionerPlugin
30-
from aminator.util.linux import command, Chroot
30+
from aminator.util.linux import command
3131

3232
__all__ = ('AnsibleProvisionerPlugin',)
3333
log = logging.getLogger(__name__)
@@ -49,40 +49,6 @@ def add_plugin_args(self):
4949
ansible_config.add_argument('-ev', '--extra-vars', dest='extravars', help='A set of additional key=value variables to be used in the playbook',
5050
action=conf_action(self._config.plugins[self.full_name]))
5151

52-
53-
def provision(self):
54-
""" The main provisioning flow """
55-
56-
context = self._config.context
57-
58-
log.debug('Pre chroot command block')
59-
self._pre_chroot_block()
60-
61-
log.debug('Entering chroot at {0}'.format(self._mountpoint))
62-
63-
with Chroot(self._mountpoint):
64-
log.debug('Inside chroot')
65-
66-
result = self._write_local_inventory()
67-
if not result:
68-
log.critical('Could not write local inventory file: {0.std_err}'.format(result.result))
69-
return False
70-
71-
result = self._provision_package()
72-
if not result.success:
73-
log.critical('Installation of {0} failed: {1.std_err}'.format(context.package.arg, result.result))
74-
return False
75-
self._store_package_metadata()
76-
77-
self._ansible_cleanup()
78-
79-
log.debug('Exited chroot')
80-
81-
log.debug('Post chroot command block')
82-
self._post_chroot_block()
83-
84-
log.info('Provisioning succeeded!')
85-
return True
8652

8753

8854
def _write_local_inventory(self):
@@ -136,6 +102,11 @@ def _copy_playbooks(self):
136102
def _provision_package(self):
137103
""" Sets up the command to get Ansible to run """
138104

105+
result = self._write_local_inventory()
106+
if not result:
107+
log.critical('Could not write local inventory file: {0.std_err}'.format(result.result))
108+
return False
109+
139110
context = self._config.context
140111
config = self._config.plugins[self.full_name]
141112
extra_vars = config.get('extravars', '')
@@ -148,6 +119,8 @@ def _provision_package(self):
148119
def _store_package_metadata(self):
149120
""" Store metadata about the AMI created """
150121

122+
self._ansible_cleanup()
123+
151124
context = self._config.context
152125
config = self._config.plugins[self.full_name]
153126
metadata = {}

0 commit comments

Comments
 (0)