summaryrefslogtreecommitdiffstats
path: root/deploy/ansible_plugins/callback/playbook_done.py
diff options
context:
space:
mode:
Diffstat (limited to 'deploy/ansible_plugins/callback/playbook_done.py')
-rw-r--r--deploy/ansible_plugins/callback/playbook_done.py111
1 files changed, 111 insertions, 0 deletions
diff --git a/deploy/ansible_plugins/callback/playbook_done.py b/deploy/ansible_plugins/callback/playbook_done.py
new file mode 100644
index 00000000..4784ff63
--- /dev/null
+++ b/deploy/ansible_plugins/callback/playbook_done.py
@@ -0,0 +1,111 @@
+#!/usr/bin/env python
+#
+# Copyright 2014 Huawei Technologies Co. Ltd
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+"""Ansible playbook callback after a playbook run has completed."""
+import sys
+
+from distutils.version import LooseVersion
+from ansible import __version__ as __ansible_version__
+from ansible.plugins.callback import CallbackBase
+
+compass_bin = "/opt/compass/bin"
+sys.path.append(compass_bin)
+
+import switch_virtualenv # noqa: F401
+
+from compass.apiclient.restful import Client # noqa: E402
+from compass.utils import flags # noqa: E402
+
+
+flags.add('compass_server',
+ help='compass server url',
+ default='http://compass-deck/api')
+flags.add('compass_user_email',
+ help='compass user email',
+ default='admin@huawei.com')
+flags.add('compass_user_password',
+ help='compass user password',
+ default='admin')
+
+
+class CallbackModule(CallbackBase):
+ CALLBACK_VERSION = 2.0
+ CALLBACK_TYPE = 'notification'
+ CALLBACK_NAME = 'playbook_done'
+ CALLBACK_NEEDS_WHITELIST = True
+
+ def __init__(self):
+ super(CallbackModule, self).__init__()
+
+ self.play = None
+ self.loader = None
+ self.disabled = False
+ try:
+ self.client = self._get_client()
+ except Exception:
+ self.disabled = True
+ self._display.error("No compass server found"
+ "disabling this plugin")
+
+ def _get_client(self):
+ return Client(flags.OPTIONS.compass_server)
+
+ def _login(self, client):
+ """get apiclient token."""
+ status, resp = client.get_token(
+ flags.OPTIONS.compass_user_email,
+ flags.OPTIONS.compass_user_password
+ )
+ self._display.warning(
+ 'login status: %s, resp: %s' %
+ (status, resp)
+ )
+ if status >= 400:
+ raise Exception(
+ 'failed to login %s with user %s',
+ flags.OPTIONS.compass_server,
+ flags.OPTIONS.compass_user_email
+ )
+ return resp['token']
+
+ def v2_playbook_on_play_start(self, play):
+ self.play = play
+ self.loader = self.play.get_loader()
+ return
+
+ def v2_playbook_on_stats(self, stats):
+ if LooseVersion(__ansible_version__) < LooseVersion("2.4"):
+ all_vars = self.play.get_variable_manager().get_vars(self.loader)
+ else:
+ all_vars = self.play.get_variable_manager().get_vars()
+ host_vars = all_vars["hostvars"]
+ hosts = sorted(stats.processed.keys())
+ cluster_name = host_vars[hosts[0]]['cluster_name']
+ self._display.warning("cluster_name %s" % cluster_name)
+
+ failures = False
+ unreachable = False
+
+ for host in hosts:
+ summary = stats.summarize(host)
+
+ if summary['failures'] > 0:
+ failures = True
+ if summary['unreachable'] > 0:
+ unreachable = True
+
+ if failures or unreachable:
+ return
olor: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */ }
# Copyright 2016 Red Hat, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
# == Class: tripleo::profile::base::ceph::rgw
#
# Ceph RadosGW profile for tripleo
#
# === Parameters
#
# [*civetweb_bind_ip*]
#   IP address where to bind the RGW civetweb instance
#   (Optional) Defaults to 127.0.0.1
#
# [*civetweb_bind_port*]
#   PORT where to bind the RGW civetweb instance
#   (Optional) Defaults to 8080
#
# [*keystone_admin_token*]
#   The keystone admin token
#
# [*rgw_keystone_version*] The api version for keystone.
#   Possible values 'v2.0', 'v3'
#   Optional. Default is 'v2.0'
#
# [*keystone_url*]
#   The internal or admin url for keystone
#
# [*rgw_key*]
#   The cephx key for the RGW client service
#
# [*step*]
#   (Optional) The current step in deployment. See tripleo-heat-templates
#   for more details.
#   Defaults to hiera('step')
#
class tripleo::profile::base::ceph::rgw (
  $keystone_admin_token,
  $keystone_url,
  $rgw_key,
  $civetweb_bind_ip            = '127.0.0.1',
  $civetweb_bind_port          = '8080',
  $rgw_keystone_version        = 'v2.0',
  $step                        = hiera('step'),
) {

  include ::tripleo::profile::base::ceph

  if $step >= 3 {
    $rgw_name = hiera('ceph::profile::params::rgw_name', 'radosgw.gateway')
    $civetweb_bind_ip_real = normalize_ip_for_uri($civetweb_bind_ip)
    include ::ceph::params
    include ::ceph::profile::client
    ceph::rgw { $rgw_name:
      frontend_type => 'civetweb',
      rgw_frontends => "civetweb port=${civetweb_bind_ip_real}:${civetweb_bind_port}",
      user          => 'ceph',
    }
    ceph::key { "client.${rgw_name}":
      secret  => $rgw_key,
      cap_mon => 'allow *',
      cap_osd => 'allow *',
      inject  => true,
    }
  }

  if $step >= 4 {
    if $rgw_keystone_version == 'v2.0' {
      ceph::rgw::keystone { $rgw_name:
        rgw_keystone_accepted_roles => ['admin', '_member_', 'Member'],
        use_pki                     => false,
        rgw_keystone_admin_token    => $keystone_admin_token,
        rgw_keystone_url            => $keystone_url,
        user                        => 'ceph',
      }
    }
    else
    {
      ceph::rgw::keystone { $rgw_name:
        rgw_keystone_accepted_roles => ['admin', '_member_', 'Member'],
        use_pki                     => false,
        rgw_keystone_url            => $keystone_url,
        rgw_keystone_version        => $rgw_keystone_version,
        user                        => 'ceph',
      }
    }
  }
}