Merge branch 'master' into dry-run
This commit is contained in:
commit
f6d04062a5
@ -44,7 +44,7 @@ def deploy():
|
||||
signals.connect(node1, mariadb_service1)
|
||||
|
||||
# RABBIT
|
||||
rabbitmq_service1 = vr.create('rabbitmq1', 'resources/rabbitmq_service', {'management_port': 15672, 'port': 5672, 'node_name': 'rabbitmq_service1'})[0]
|
||||
rabbitmq_service1 = vr.create('rabbitmq1', 'resources/rabbitmq_service', {'management_port': 15672, 'port': 5672})[0]
|
||||
openstack_vhost = vr.create('openstack_vhost', 'resources/rabbitmq_vhost/', {'vhost_name': 'openstack'})[0]
|
||||
openstack_rabbitmq_user = vr.create('openstack_rabbitmq_user', 'resources/rabbitmq_user/', {'user_name': 'openstack', 'password': 'openstack_password'})[0]
|
||||
|
||||
|
2
main.yml
2
main.yml
@ -15,7 +15,7 @@
|
||||
- apt: name=python-pudb state=present
|
||||
#- apt: name=python-pip state=present
|
||||
- shell: pip install docker-py==1.1.0
|
||||
- shell: pip install python-keystoneclient==1.5.0
|
||||
- apt: name=python-keystoneclient state=present
|
||||
|
||||
- apt: name=redis-server state=present
|
||||
#- apt: name=python-redis state=present
|
||||
|
9
resources/ansible_local/actions/run.yaml
Normal file
9
resources/ansible_local/actions/run.yaml
Normal file
@ -0,0 +1,9 @@
|
||||
- hosts: localhost
|
||||
sudo: yes
|
||||
vars:
|
||||
var1: 'playbook'
|
||||
roles:
|
||||
- { role: "test_role" }
|
||||
tasks:
|
||||
- debug: msg="VAR1 value is {{var1}}"
|
||||
- fail: msg='just test failure'
|
@ -0,0 +1,4 @@
|
||||
|
||||
var1: initial
|
||||
uuid: stuff
|
||||
def1: the_same
|
1
resources/ansible_local/actions/test_role/tasks/main.yml
Normal file
1
resources/ansible_local/actions/test_role/tasks/main.yml
Normal file
@ -0,0 +1 @@
|
||||
- debug: msg="Variable1 {{ var1 }} with uuid {{ uuid }} and default var {{ def1 }}"
|
11
resources/ansible_local/meta.yaml
Normal file
11
resources/ansible_local/meta.yaml
Normal file
@ -0,0 +1,11 @@
|
||||
id: ansible_sample
|
||||
handler: ansible_playbook
|
||||
version: 0.0.1
|
||||
input:
|
||||
var1:
|
||||
type: str!
|
||||
value: meta
|
||||
uuid:
|
||||
type: str!
|
||||
value: 'aa1das1231'
|
||||
|
6
resources/ansible_remote/actions/run.yaml
Normal file
6
resources/ansible_remote/actions/run.yaml
Normal file
@ -0,0 +1,6 @@
|
||||
- hosts: '*'
|
||||
sudo: yes
|
||||
vars:
|
||||
default1: playbook
|
||||
tasks:
|
||||
- debug: msg="my message {{default1}}"
|
16
resources/ansible_remote/meta.yaml
Normal file
16
resources/ansible_remote/meta.yaml
Normal file
@ -0,0 +1,16 @@
|
||||
id: ansible_sample
|
||||
handler: ansible_playbook
|
||||
version: 0.0.1
|
||||
input:
|
||||
ip:
|
||||
type: str!
|
||||
value:
|
||||
ssh_user:
|
||||
type: str!
|
||||
value:
|
||||
ssh_key:
|
||||
type: str!
|
||||
value:
|
||||
default1:
|
||||
type: str!
|
||||
value: meta
|
@ -2,6 +2,6 @@
|
||||
sudo: yes
|
||||
tasks:
|
||||
- name: install python-keystoneclient
|
||||
shell: pip install python-keystoneclient
|
||||
shell: apt-get install python-keystoneclient
|
||||
- name: keystone role
|
||||
keystone_user: endpoint=http://{{keystone_host}}:{{keystone_port}}/v2.0/ token={{admin_token}} user={{user_name}} tenant={{tenant_name}} role={{role_name}} state=present
|
||||
|
@ -2,6 +2,6 @@
|
||||
sudo: yes
|
||||
tasks:
|
||||
- name: install python-keystoneclient
|
||||
shell: pip install python-keystoneclient
|
||||
shell: apt-get install python-keystoneclient
|
||||
- name: keystone tenant
|
||||
keystone_user: endpoint=http://{{keystone_host}}:{{keystone_port}}/v2.0/ token={{admin_token}} tenant={{tenant_name}} state=present
|
||||
|
@ -2,6 +2,6 @@
|
||||
sudo: yes
|
||||
tasks:
|
||||
- name: install python-keystoneclient
|
||||
shell: pip install python-keystoneclient
|
||||
shell: apt-get install python-keystoneclient
|
||||
- name: keystone user
|
||||
keystone_user: endpoint=http://{{ keystone_host }}:{{ keystone_port }}/v2.0/ token={{ admin_token }} user={{ user_name }} password={{ user_password }} tenant={{ tenant_name }} state=present
|
||||
|
@ -5,12 +5,8 @@ $management_port = "${resource['input']['management_port']['value']}"
|
||||
$node_name = $resource['input']['node_name']['value']
|
||||
|
||||
class { '::rabbitmq':
|
||||
service_manage => false,
|
||||
service_manage => true,
|
||||
port => $port,
|
||||
management_port => $management_port,
|
||||
delete_guest_user => true,
|
||||
environment_variables => {
|
||||
'RABBITMQ_NODENAME' => $node_name,
|
||||
'RABBITMQ_SERVICENAME' => 'RabbitMQ'
|
||||
}
|
||||
}
|
||||
|
@ -4,4 +4,3 @@
|
||||
- new_rabbitmq_user: user={{user_name}}
|
||||
vhost={{vhost_name}}
|
||||
state=absent
|
||||
node={{node_name}}
|
||||
|
@ -8,4 +8,3 @@
|
||||
read_priv=.*
|
||||
write_priv=.*
|
||||
state=present
|
||||
node={{node_name}}
|
||||
|
@ -2,9 +2,6 @@ id: rabbitmq_user
|
||||
handler: ansible
|
||||
version: 1.0.0
|
||||
input:
|
||||
node_name:
|
||||
schema: str!
|
||||
value:
|
||||
user_name:
|
||||
schema: str!
|
||||
value: openstack
|
||||
|
@ -3,4 +3,3 @@
|
||||
tasks:
|
||||
- new_rabbitmq_vhost: name={{vhost_name}}
|
||||
state=absent
|
||||
node={{node_name}}
|
||||
|
@ -2,5 +2,4 @@
|
||||
sudo: yes
|
||||
tasks:
|
||||
- new_rabbitmq_vhost: name={{vhost_name}}
|
||||
node={{node_name}}
|
||||
state=present
|
||||
|
@ -2,9 +2,6 @@ id: rabbitmq_vhost
|
||||
handler: ansible
|
||||
version: 1.0.0
|
||||
input:
|
||||
node_name:
|
||||
schema: str!
|
||||
value:
|
||||
vhost_name:
|
||||
schema: str!
|
||||
value: openstack
|
||||
|
@ -351,19 +351,19 @@ def init_cli_resource():
|
||||
pass
|
||||
|
||||
@resource.command()
|
||||
@click.argument('resource_name')
|
||||
@click.argument('action_name')
|
||||
@click.argument('action')
|
||||
@click.argument('resource')
|
||||
@click.option('-d', '--dry-run', default=False, is_flag=True)
|
||||
@click.option('-m', '--dry-run-mapping', default='{}')
|
||||
def action(dry_run_mapping, dry_run, action_name, resource_name):
|
||||
def action(dry_run_mapping, dry_run, action, resource):
|
||||
if dry_run:
|
||||
dry_run_executor = DryRunExecutor(mapping=json.loads(dry_run_mapping))
|
||||
|
||||
click.echo(
|
||||
'action {} for resource {}'.format(action_name, resource_name)
|
||||
'action {} for resource {}'.format(action, resource)
|
||||
)
|
||||
r = sresource.load(resource_name)
|
||||
actions.resource_action(r, action_name)
|
||||
actions.resource_action(sresource.load(resource), action)
|
||||
|
||||
|
||||
if dry_run:
|
||||
click.echo('EXECUTED:')
|
||||
|
@ -1,12 +1,13 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from solar.core.handlers.ansible import Ansible
|
||||
from solar.core.handlers.ansible_template import AnsibleTemplate
|
||||
from solar.core.handlers.ansible_playbook import AnsiblePlaybook
|
||||
from solar.core.handlers.base import Empty
|
||||
from solar.core.handlers.puppet import Puppet
|
||||
from solar.core.handlers.shell import Shell
|
||||
|
||||
|
||||
HANDLERS = {'ansible': Ansible,
|
||||
'puppet': Puppet,
|
||||
HANDLERS = {'ansible': AnsibleTemplate,
|
||||
'ansible_playbook': AnsiblePlaybook,
|
||||
'shell': Shell,
|
||||
'none': Empty}
|
||||
|
||||
|
51
solar/solar/core/handlers/ansible_playbook.py
Normal file
51
solar/solar/core/handlers/ansible_playbook.py
Normal file
@ -0,0 +1,51 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import os
|
||||
|
||||
from ansible.playbook import PlayBook
|
||||
from ansible import utils
|
||||
from ansible import callbacks
|
||||
import ansible.constants as C
|
||||
|
||||
from solar.core.handlers import base
|
||||
from solar import errors
|
||||
|
||||
|
||||
class AnsiblePlaybook(base.BaseHandler):
|
||||
|
||||
def action(self, resource, action):
|
||||
action_file = os.path.join(
|
||||
resource.metadata['actions_path'],
|
||||
resource.metadata['actions'][action])
|
||||
stats = callbacks.AggregateStats()
|
||||
playbook_cb = callbacks.PlaybookCallbacks(verbose=utils.VERBOSITY)
|
||||
runner_cb = callbacks.PlaybookRunnerCallbacks(stats, verbose=utils.VERBOSITY)
|
||||
|
||||
variables = resource.args_dict()
|
||||
remote_user = variables.get('ssh_user') or C.DEFAULT_REMOTE_USER
|
||||
private_key_file = variables.get('ssh_key') or C.DEFAULT_PRIVATE_KEY_FILE
|
||||
if variables.get('ip'):
|
||||
host = variables['ip']
|
||||
transport = C.DEFAULT_TRANSPORT
|
||||
else:
|
||||
host = 'localhost'
|
||||
transport = 'local'
|
||||
|
||||
play = PlayBook(
|
||||
playbook=action_file,
|
||||
remote_user=remote_user,
|
||||
host_list = [host],
|
||||
private_key_file=private_key_file,
|
||||
extra_vars=variables,
|
||||
callbacks=playbook_cb,
|
||||
runner_callbacks=runner_cb,
|
||||
stats=stats,
|
||||
transport=transport)
|
||||
|
||||
play.run()
|
||||
summary = stats.summarize(host)
|
||||
|
||||
if summary.get('unreachable') or summary.get('failures'):
|
||||
raise errors.SolarError(
|
||||
'Ansible playbook %s failed with next summary %s',
|
||||
action_file, summary)
|
@ -3,10 +3,10 @@ from fabric import api as fabric_api
|
||||
import os
|
||||
|
||||
from solar.core.log import log
|
||||
from solar.core.handlers.base import BaseHandler
|
||||
from solar.core.handlers.base import TempFileHandler
|
||||
|
||||
|
||||
class Ansible(BaseHandler):
|
||||
class AnsibleTemplate(TempFileHandler):
|
||||
def action(self, resource, action_name):
|
||||
inventory_file = self._create_inventory(resource)
|
||||
playbook_file = self._create_playbook(resource, action_name)
|
@ -9,6 +9,18 @@ from solar.core.log import log
|
||||
|
||||
|
||||
class BaseHandler(object):
|
||||
|
||||
def __init__(self, resources):
|
||||
self.resources = resources
|
||||
|
||||
def __enter__(self):
|
||||
return self
|
||||
|
||||
def __exit__(self, exc, value, traceback):
|
||||
return
|
||||
|
||||
|
||||
class TempFileHandler(BaseHandler):
|
||||
def __init__(self, resources):
|
||||
self.dst = tempfile.mkdtemp()
|
||||
self.resources = resources
|
||||
|
@ -1,10 +1,10 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from fabric import api as fabric_api
|
||||
|
||||
from solar.core.handlers.base import BaseHandler
|
||||
from solar.core.handlers.base import TempFileHandler
|
||||
|
||||
|
||||
class Shell(BaseHandler):
|
||||
class Shell(TempFileHandler):
|
||||
def action(self, resource, action_name):
|
||||
action_file = self._compile_action_file(resource, action_name)
|
||||
fabric_api.local('bash {}'.format(action_file))
|
||||
|
Loading…
Reference in New Issue
Block a user