summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeffrey Zhang <jeffrey.zhang@99cloud.net>2016-05-17 20:16:42 +0800
committerJeffrey Zhang <jeffrey.zhang@99cloud.net>2016-05-24 19:53:31 +0800
commit491822c510ca9010d36aeecbcf7716828088cb1b (patch)
treea42aec37e58baa8fd2f610ed82405cbf2f8d988f
parentc98e9c44f23d14867e4dddea88fe9a9f7aa50dd6 (diff)
downloadkolla-491822c510ca9010d36aeecbcf7716828088cb1b.tar.gz
kolla-491822c510ca9010d36aeecbcf7716828088cb1b.zip
Bump the ansible to 2
DocImpact Change-Id: I3cdfbf84919de80f535c030bd146787ecda40dec partial-Implements: blueprint ansible2
-rw-r--r--.gitignore3
-rw-r--r--ansible/action_plugins/merge_configs.py97
-rw-r--r--ansible/library/kolla_docker.py21
-rw-r--r--ansible/roles/mariadb/tasks/start.yml6
-rw-r--r--dev/vagrant/bootstrap.sh2
-rwxr-xr-xtools/setup_gate.sh2
6 files changed, 68 insertions, 63 deletions
diff --git a/.gitignore b/.gitignore
index 7cae5350e..5e26231d8 100644
--- a/.gitignore
+++ b/.gitignore
@@ -43,5 +43,8 @@ dev/vagrant/storage/
# Files created by reno build
releasenotes/build
+# Files generated by Ansible
+ansible/site.retry
+
# Others
.DS_Store
diff --git a/ansible/action_plugins/merge_configs.py b/ansible/action_plugins/merge_configs.py
index 2d2b6545b..b5df51fdc 100644
--- a/ansible/action_plugins/merge_configs.py
+++ b/ansible/action_plugins/merge_configs.py
@@ -18,81 +18,70 @@ from ConfigParser import ConfigParser
from cStringIO import StringIO
import os
-from ansible.runner.return_data import ReturnData
-from ansible import utils
-from ansible.utils import template
+from ansible.plugins.action import ActionBase
-class ActionModule(object):
+class ActionModule(ActionBase):
TRANSFERS_FILES = True
- def __init__(self, runner):
- self.runner = runner
-
- def read_config(self, source, inject, config):
+ def read_config(self, source, config):
# Only use config if present
if os.access(source, os.R_OK):
- # template the source data locally & get ready to transfer
- resultant = template.template_from_file(self.runner.basedir,
- source, inject)
-
- # Read in new results and merge this with the existing config
- fakefile = StringIO(resultant)
+ with open(source, 'r') as f:
+ template_data = f.read()
+ result = self._templar.template(template_data)
+ fakefile = StringIO(result)
config.readfp(fakefile)
fakefile.close()
- def run(self, conn, tmp, module_name, module_args, inject,
- complex_args=None, **kwargs):
- args = {}
- if complex_args:
- args.update(complex_args)
- args.update(utils.parse_kv(module_args))
-
- dest = args.get('dest')
- extra_vars = args.get('vars')
- sources = args.get('sources')
-
- if extra_vars:
- # Extend 'inject' args used in templating
- if isinstance(extra_vars, dict):
- inject.update(extra_vars)
- else:
- inject.update(utils.parse_kv(extra_vars))
-
- # Catch the case where sources is a str()
+ def run(self, tmp=None, task_vars=None):
+
+ if task_vars is None:
+ task_vars = dict()
+ result = super(ActionModule, self).run(tmp, task_vars)
+
+ if not tmp:
+ tmp = self._make_tmp_path()
+
+ sources = self._task.args.get('sources', None)
+ extra_vars = self._task.args.get('vars', list())
+
if not isinstance(sources, list):
sources = [sources]
+ temp_vars = task_vars.copy()
+ temp_vars.update(extra_vars)
+
config = ConfigParser()
+ old_vars = self._templar._available_variables
+ self._templar.set_available_variables(temp_vars)
for source in sources:
- # template the source string
- source = template.template(self.runner.basedir, source, inject)
-
- try:
- self.read_config(source, inject, config)
- except Exception as e:
- return ReturnData(conn=conn, comm_ok=False,
- result={'failed': True, 'msg': str(e)})
+ self.read_config(source, config)
+ self._templar.set_available_variables(old_vars)
# Dump configparser to string via an emulated file
+
fakefile = StringIO()
config.write(fakefile)
- # Template the file to fill out any variables
- content = template.template(self.runner.basedir, fakefile.getvalue(),
- inject)
+
+ remote_path = self._connection._shell.join_path(tmp, 'src')
+ xfered = self._transfer_data(remote_path, fakefile.getvalue())
fakefile.close()
- # Ship this content over to a new file for use with the copy module
- xfered = self.runner._transfer_str(conn, tmp, 'source', content)
+ new_module_args = self._task.args.copy()
+ del new_module_args['vars']
+ del new_module_args['sources']
- copy_module_args = dict(
- src=xfered,
- dest=dest,
- original_basename=os.path.basename(source),
- follow=True,
+ new_module_args.update(
+ dict(
+ src=xfered
+ )
)
- return self.runner._execute_module(conn, tmp, 'copy', '',
- inject=inject,
- complex_args=copy_module_args)
+
+ result.update(self._execute_module(module_name='copy',
+ module_args=new_module_args,
+ task_vars=task_vars,
+ tmp=tmp))
+ return result
diff --git a/ansible/library/kolla_docker.py b/ansible/library/kolla_docker.py
index 50d37deeb..e8e39490d 100644
--- a/ansible/library/kolla_docker.py
+++ b/ansible/library/kolla_docker.py
@@ -683,7 +683,8 @@ def generate_module():
]
return AnsibleModule(
argument_spec=argument_spec,
- required_together=required_together
+ required_together=required_together,
+ bypass_checks=True
)
@@ -691,15 +692,21 @@ def generate_nested_module():
module = generate_module()
# We unnest the common dict and the update it with the other options
- new_args = module.params.get('common_options')
- new_args.update(module._load_params()[0])
- module.params = new_args
+ new_args = module.params.pop('common_options', dict())
+
+ # NOTE(jeffrey4l): merge the environment
+ env = module.params.pop('environment', dict())
+ if env:
+ new_args['environment'].update(env)
+
+ for key, value in module.params.iteritems():
+ if key in new_args and value is None:
+ continue
+ new_args[key] = value
# Override ARGS to ensure new args are used
- global MODULE_ARGS
global MODULE_COMPLEX_ARGS
- MODULE_ARGS = ''
- MODULE_COMPLEX_ARGS = json.dumps(module.params)
+ MODULE_COMPLEX_ARGS = json.dumps(new_args)
# Reprocess the args now that the common dict has been unnested
return generate_module()
diff --git a/ansible/roles/mariadb/tasks/start.yml b/ansible/roles/mariadb/tasks/start.yml
index e75b3e0d1..3eff6ebee 100644
--- a/ansible/roles/mariadb/tasks/start.yml
+++ b/ansible/roles/mariadb/tasks/start.yml
@@ -14,6 +14,8 @@
( groups['mariadb'] | length ) == 1 or
( delegate_host == 'None' and inventory_hostname != groups['mariadb'][0] )
+# TODO(jeffrey4l), remove the task check when the wair_for bug is fixed
+# https://github.com/ansible/ansible-modules-core/issues/2788
- name: Waiting for MariaDB service to be ready
wait_for:
host: "{{ hostvars[inventory_hostname]['ansible_' + api_interface]['ipv4']['address'] }}"
@@ -21,3 +23,7 @@
connect_timeout: 1
timeout: 60
search_regex: "MariaDB"
+ register: check_mariadb_port
+ until: check_mariadb_port | success
+ retries: 10
+ delay: 6
diff --git a/dev/vagrant/bootstrap.sh b/dev/vagrant/bootstrap.sh
index ace58ecba..a6c6de0ca 100644
--- a/dev/vagrant/bootstrap.sh
+++ b/dev/vagrant/bootstrap.sh
@@ -152,7 +152,7 @@ function configure_operator {
exit 1
fi
- pip install --upgrade "ansible<2" python-openstackclient python-neutronclient tox
+ pip install --upgrade "ansible>=2" python-openstackclient python-neutronclient tox
pip install ${KOLLA_PATH}
diff --git a/tools/setup_gate.sh b/tools/setup_gate.sh
index e7c75425d..91caa72dc 100755
--- a/tools/setup_gate.sh
+++ b/tools/setup_gate.sh
@@ -98,7 +98,7 @@ function setup_ansible {
mkdir /tmp/kolla
# TODO(SamYaple): Move to virtualenv
- sudo -H pip install -U "ansible<2" "docker-py>=1.6.0" "python-openstackclient" "python-neutronclient"
+ sudo -H pip install -U "ansible>=2" "docker-py>=1.6.0" "python-openstackclient" "python-neutronclient"
detect_distro
setup_inventory