ci-cd-pipeline-app-murano/murano-apps/Puppet/package/Classes/PuppetServer.yaml

126 lines
3.5 KiB
YAML

# 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.
Namespaces:
=: org.openstack.ci_cd_pipeline_murano_app.puppet
conf: io.murano.configuration
sys: io.murano.system
net: org.openstack.ci_cd_pipeline_murano_app.puppet.net
Name: PuppetServer
Properties:
masterInstance:
Contract: $.class(PuppetInstance).notNull()
clients:
Contract:
- $.class('org.openstack.ci_cd_pipeline_murano_app.puppet.PuppetClient')
Usage: Out
Default: []
manifest:
Contract: $.string().notNull()
_hosts:
Contract: $.class(net:Hosts)
Usage: Out
Methods:
.init:
Body:
- $this.hosts: new(net:Hosts)
configure:
Body:
- $this._configureHosts()
- $this._installPuppetModules()
- $data: dict('environment:production:manifest' => $this.manifest)
- $this.masterInstance.putHieraData($data)
- $resources: new(sys:Resources)
- $this.masterInstance.applyManifest(
$resources.string('scripts/server/puppet_server.pp'))
- $this.clients.pselect($.configure())
- $this.clients.pselect($.testRun())
# sign obtained requests
- $this.clients.pselect($this.signClientCertificate($.role))
_configureHosts:
Body:
- $this._hosts: new(net:Hosts)
- $this._hosts.addHostByInstance($this.masterInstance, 'puppet')
- $this.clients.pselect(
$this._hosts.addHostByInstance($.instance, $.role))
- $this._hosts.applyTo($this.masterInstance)
- $this.clients.pselect($this._hosts.applyTo($.instance))
addClient:
Arguments:
- client:
Contract: $.class(PuppetClient).notNull()
Body:
- $this.clients: $this.clients.append($client)
#
# Sign client's certificate request
#
signClientCertificate:
Arguments:
- name:
Contract: $.string()
Body:
# sign cerificate or check it signed erlier
# in case of redeploying
- $res: new(conf:Linux).runCommand(
$this.masterInstance.agent,
'puppet cert sign {0} || puppet cert verify {0}'.format($name)).stdout
- Return: $res
#
# Install all modules on every instance
#
_installPuppetModules:
Body:
- $modules:
- 'puppetlabs-vcsrepo'
- 'theforeman-git'
- 'theforeman-puppet'
- $this.clients.select($.instance).append($this.masterInstance).selectMany(
let(x => $) -> $modules.select(
{instance => $x, module => $}))
.select( $.instance.installPuppetModule($.module))
installDependencies:
Arguments:
- environment:
Contract: $.string().notNull()
- puppetfileLink:
Contract: $.string().notNull()
Body:
- $resources: new(sys:Resources)
- $template: $resources.yaml('InstallDependencies.template').bind(dict(
environment => $environment,
puppetfile => $puppetfileLink))
- Return: $this.masterInstance.agent.call($template, $resources)
runPuppetAgents:
Body:
- $this.clients.select($.runPuppetAgent())