From 76992260071cc366f06e8655897d77d447350c58 Mon Sep 17 00:00:00 2001 From: Monty Taylor Date: Sun, 10 Jan 2016 10:29:28 -0500 Subject: [PATCH] Add script to make ansible groups from patterns We have a set of hostname patterns which is not a thing that ansible supports in inventory files. While we can put hostname patterns into playbooks directly, that does not help us with copying hiera group files since ansible doesn't know about the groups in site.pp and puppet doesn't know about the ansible groups. Instead, do a quick expansion any time the groups.txt file changes and at the end of launch-node. It will be left to admins to run expand-groups.sh whenever they delete a node. Change-Id: I00c60748ddb2d35a3b98f78d828dabebcf065118 --- launch/launch-node.py | 1 + .../files/puppetmaster/expand-groups.sh | 31 +++++++++++++++++++ .../files/puppetmaster/groups.txt | 11 +++++++ .../manifests/puppetmaster.pp | 23 ++++++++++++++ 4 files changed, 66 insertions(+) create mode 100644 modules/openstack_project/files/puppetmaster/expand-groups.sh create mode 100644 modules/openstack_project/files/puppetmaster/groups.txt diff --git a/launch/launch-node.py b/launch/launch-node.py index dac4d485bd..d162a6ceba 100755 --- a/launch/launch-node.py +++ b/launch/launch-node.py @@ -300,6 +300,7 @@ def main(): # server if os.path.exists('/var/cache/ansible-inventory/ansible-inventory.cache'): os.unlink('/var/cache/ansible-inventory/ansible-inventory.cache') + os.system('/usr/local/bin/expand-groups.sh') if __name__ == '__main__': main() diff --git a/modules/openstack_project/files/puppetmaster/expand-groups.sh b/modules/openstack_project/files/puppetmaster/expand-groups.sh new file mode 100644 index 0000000000..4526fc056d --- /dev/null +++ b/modules/openstack_project/files/puppetmaster/expand-groups.sh @@ -0,0 +1,31 @@ +#!/bin/bash + +# Copyright 2016 IBM Corp +# +# 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. + +outdir=$(mktemp -d) +trap "rm -rf $outdir" EXIT + +outfile=$outdir/generated-groups +echo "# This file is autogenerated" > $outfile + +IFS=$'\n' +for line in $(> $outfile + ansible "~${pattern}" --list-hosts >> $outfile +done + +cp $outfile /etc/ansible/hosts/generated-groups diff --git a/modules/openstack_project/files/puppetmaster/groups.txt b/modules/openstack_project/files/puppetmaster/groups.txt new file mode 100644 index 0000000000..32294a4ef5 --- /dev/null +++ b/modules/openstack_project/files/puppetmaster/groups.txt @@ -0,0 +1,11 @@ +jenkins jenkins.*\.openstack\.org +logstash-worker logstash-worker\d+\.openstack\.org +subunit-worker subunit-worker\d+\.openstack\.org +elasticsearch elasticsearch0[1-7]\.openstack\.org +git-loadbalancer git(-fe\d+)?\.openstack\.org +git-server git\d+\.openstack\.org +pypi pypi\..*\.openstack\.org +zuul-merger zm\d+\.openstack\.org +ci-backup ci-backup-.*\.openstack\.org +afsdb afsdb.*\.openstack\.org +afs afs.*\..*\.openstack\.org diff --git a/modules/openstack_project/manifests/puppetmaster.pp b/modules/openstack_project/manifests/puppetmaster.pp index 8fea9263ed..29d4b22548 100644 --- a/modules/openstack_project/manifests/puppetmaster.pp +++ b/modules/openstack_project/manifests/puppetmaster.pp @@ -233,4 +233,27 @@ class openstack_project::puppetmaster ( group => 'root', mode => '0644', } + + file { '/etc/ansible/groups.txt': + owner => 'root', + group => 'root', + mode => '0444', + source => 'puppet:///modules/openstack_project/puppetmaster/groups.txt', + notify => Exec['expand_groups'], + } + + file { '/usr/local/bin/expand-groups.sh': + owner => 'root', + group => 'root', + mode => '0755', + source => 'puppet:///modules/openstack_project/puppetmaster/expand-groups.sh', + notify => Exec['expand_groups'], + } + + exec { 'expand_groups': + command => 'expand-groups.sh', + path => '/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin', + refreshonly => true, + } + }