Merge "Split out ansible module"

This commit is contained in:
Jenkins 2015-01-29 00:14:34 +00:00 committed by Gerrit Code Review
commit 1a5c3f7858
6 changed files with 1 additions and 217 deletions
modules.env
modules/ansible
files
library/config_management
puppet-inventory
roles/puppet/tasks
manifests
templates

@ -56,6 +56,7 @@ SOURCE_MODULES["https://github.com/puppet-community/puppet-module-puppetboard"]=
# Add modules that should be part of the openstack-infra integration test here
INTEGRATION_MODULES["https://git.openstack.org/openstack-infra/puppet-ansible"]="origin/master"
INTEGRATION_MODULES["https://git.openstack.org/openstack-infra/puppet-asterisk"]="origin/master"
INTEGRATION_MODULES["https://git.openstack.org/openstack-infra/puppet-elasticsearch"]="origin/master"
INTEGRATION_MODULES["https://git.openstack.org/openstack-infra/puppet-gerrit"]="origin/master"

@ -1,114 +0,0 @@
#!/usr/bin/python
# Copyright (c) 2014 Hewlett-Packard Development Company, L.P.
#
# This module is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This software is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this software. If not, see <http://www.gnu.org/licenses/>.
import pipes
DOCUMENTATION = '''
---
module: puppet
short_description: Runs puppet
description:
- Runs I(puppet) agent in a reliable manner
version_added: "1.5.6"
options:
timeout:
description:
- How long to wait for I(puppet) to finish.
required: false
default: 30m
puppetmaster:
description:
- The hostname of the puppetmaster to contact.
required: true
show_diff:
description:
- Should puppet return diffs of changes applied. Defaults to off to avoid leaking secret changes by default.
required: false
default: no
choices: [ "yes", "no" ]
requirements: [ puppet ]
author: Monty Taylor
'''
EXAMPLES = '''
# Run puppet and fail if anything goes wrong
- puppet
# Run puppet and timeout in 5 minutes
- puppet: timeout=5m
'''
def main():
module = AnsibleModule(
argument_spec=dict(
timeout=dict(default="30m"),
puppetmaster=dict(required=True),
show_diff=dict(
default=False, aliases=['show-diff'], type='bool'),
),
)
p = module.params
global PUPPET_CMD
PUPPET_CMD = module.get_bin_path("puppet", False)
if not PUPPET_CMD:
module.fail_json(
msg="Could not find puppet. Please ensure it is installed.")
cmd = ("timeout -s 9 %(timeout)s %(puppet_cmd)s agent --onetime"
" --server %(puppetmaster)s"
" --ignorecache --no-daemonize --no-usecacheonfailure --no-splay"
" --detailed-exitcodes --verbose") % dict(
timeout=pipes.quote(p['timeout']), puppet_cmd=PUPPET_CMD,
puppetmaster=pipes.quote(p['puppetmaster']))
if p['show_diff']:
cmd += " --show-diff"
rc, stdout, stderr = module.run_command(cmd)
if rc == 0:
# success
module.exit_json(rc=rc, changed=False, stdout=stdout)
elif rc == 1:
# rc==1 could be because it's disabled
# rc==1 could also mean there was a compilation failure
disabled = "administratively disabled" in stdout
if disabled:
msg = "puppet is disabled"
else:
msg = "puppet did not run"
module.exit_json(
rc=rc, disabled=disabled, msg=msg,
error=True, stdout=stdout, stderr=stderr)
elif rc == 2:
# success with changes
module.exit_json(rc=0, changed=True)
elif rc == 124:
# timeout
module.exit_json(
rc=rc, msg="%s timed out" % cmd, stdout=stdout, stderr=stderr)
else:
# failure
module.fail_json(
rc=rc, msg="%s failed with return code: %d" % (cmd, rc),
stdout=stdout, stderr=stderr)
# import module snippets
from ansible.module_utils.basic import *
main()

@ -1,30 +0,0 @@
#!/usr/bin/env python
# Copyright (c) 2014 Hewlett-Packard Development Company, L.P.
#
# 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.
import json
import subprocess
output = [
x.split()[1][1:-1] for x in subprocess.check_output(
["puppet","cert","list","-a"]).split('\n')
if x.startswith('+')
]
data = {
'_meta': {'hostvars': dict()},
'ungrouped': output,
}
print json.dumps(data, sort_keys=True, indent=2)

@ -1,4 +0,0 @@
---
- name: run puppet
puppet:
puppetmaster: "{{puppetmaster}}"

@ -1,65 +0,0 @@
# == Class: ansible
#
class ansible (
$ansible_hostfile = '/usr/local/bin/puppet-inventory'
) {
include logrotate
include pip
package { 'ansible':
ensure => latest,
provider => pip,
}
if ! defined(File['/etc/ansible']) {
file { '/etc/ansible':
ensure => directory,
}
}
file { '/etc/ansible/ansible.cfg':
ensure => present,
mode => '0644',
owner => 'root',
group => 'root',
content => template('ansible/ansible.cfg.erb'),
require => File['/etc/ansible'],
}
file { '/usr/local/bin/puppet-inventory':
ensure => present,
mode => '0755',
owner => 'root',
group => 'root',
source => 'puppet:///modules/ansible/puppet-inventory',
}
file { '/etc/ansible/roles':
ensure => directory,
recurse => true,
source => 'puppet:///modules/ansible/roles',
require => File['/etc/ansible'],
}
file { '/etc/ansible/library':
ensure => directory,
recurse => true,
source => 'puppet:///modules/ansible/library',
require => File['/etc/ansible'],
}
include logrotate
logrotate::file { 'ansible':
log => '/var/log/ansible.log',
options => [
'compress',
'copytruncate',
'missingok',
'rotate 7',
'daily',
'notifempty',
],
}
}

@ -1,4 +0,0 @@
[defaults]
hostfile=<%= @ansible_hostfile %>
library=/usr/share/ansible:/etc/ansible/library
log_path=/var/log/ansible.log