Merge branch 'master' of /git/ansible
This commit is contained in:
commit
3e73b9b62f
2 changed files with 120 additions and 9 deletions
|
@ -1,18 +1,22 @@
|
|||
executable scripts to use ansible on the system
|
||||
ans-needs-reboot - check which hosts need to be rebooted due to kernel or
|
||||
other critical updates
|
||||
|
||||
describe-instances is to get a simple list of all the instances under an
|
||||
account in the eucalyptus cloudlet.
|
||||
ans-vhost-freemem - display freememory per vhost
|
||||
|
||||
normal invocation:
|
||||
auth-keys-from-fas - run to pull ssh auth keys from fas for users to push
|
||||
onto systems
|
||||
|
||||
freezelist - run to see if a host is included in the change-freeze or not
|
||||
|
||||
sudo -i watch /srv/web/infra/ansible/scripts/describe-instances
|
||||
ok-nagios - tells nagios to start notifying again
|
||||
|
||||
so you can see it update/change
|
||||
shutup-nagios - tells nagios to shut the hell up
|
||||
|
||||
which_playbook - lets you look up which playbook (and how to run it) for
|
||||
running the deployment/maintenance playbook for any given
|
||||
host
|
||||
ex: which_playbook kernel01.qa.fedoraproject.org
|
||||
|
||||
|
||||
|
||||
terminate-instances <ip or id>
|
||||
To shutdown an instance just run:
|
||||
|
||||
sudo -i /srv/web/infra/ansible/scripts/terminate-instances ip-of-instance
|
||||
|
|
107
scripts/which_playbook
Executable file
107
scripts/which_playbook
Executable file
|
@ -0,0 +1,107 @@
|
|||
#!/usr/bin/python -tt
|
||||
# skvidal
|
||||
# gplv2
|
||||
|
||||
# takes hostnames as arguments
|
||||
# returns the group or host playbook which will setup/configure this host
|
||||
# or outputs an error message if there is no playbook for that host
|
||||
|
||||
#NB - this does not read the actual hosts entries from the plays in the
|
||||
# playbooks b/c that captures lots of issues with delegated hosts and VM and
|
||||
# silliness. It just uses the filename :)
|
||||
|
||||
# takes 2 dirs:
|
||||
# - host-specific-playbooks
|
||||
# - group-specific-playbooks
|
||||
|
||||
# looks for a host playbook matching the hostname first
|
||||
# looks up groups for that host specified
|
||||
# looks if any of the groups have playbooks
|
||||
# if more than one playbook exists - emits an error (either a group AND a
|
||||
# hostname playbook or a 2 group playbooks)
|
||||
# output the command to run
|
||||
# if it is a group playbook include the --limit option
|
||||
|
||||
|
||||
|
||||
import os
|
||||
import sys
|
||||
import ansible.inventory
|
||||
from optparse import OptionParser
|
||||
|
||||
host_path = '/srv/web/infra/ansible/playbooks/hosts'
|
||||
group_path = '/srv/web/infra/ansible/playbooks/groups'
|
||||
pb_extension = '.yml'
|
||||
|
||||
|
||||
|
||||
def main():
|
||||
group_playbooks = []
|
||||
for (d, dirs, files) in os.walk(group_path):
|
||||
for fn in files:
|
||||
if fn.endswith(pb_extension):
|
||||
group_playbooks.append(d + '/' + fn)
|
||||
|
||||
|
||||
|
||||
host_playbooks = []
|
||||
for (d, dirs, files) in os.walk(host_path):
|
||||
for fn in files:
|
||||
if fn.endswith(pb_extension):
|
||||
host_playbooks.append(d + '/' + fn)
|
||||
|
||||
|
||||
if not host_playbooks and not group_playbooks:
|
||||
print "No Playbooks found - that seems unlikely"
|
||||
return 1
|
||||
|
||||
|
||||
parser = OptionParser(version = "1.0")
|
||||
parser.add_option('-i', dest='inventory', default=None,
|
||||
help="Path to inventory file/dir")
|
||||
opts,hosts = parser.parse_args(sys.argv[1:])
|
||||
|
||||
if opts.inventory:
|
||||
inv = ansible.inventory.Inventory(host_list=opts.inventory)
|
||||
else:
|
||||
inv = ansible.inventory.Inventory()
|
||||
|
||||
|
||||
for host in hosts:
|
||||
matched_host = None
|
||||
matched_group = None
|
||||
for h_pb in host_playbooks:
|
||||
if matched_host:
|
||||
break
|
||||
if host == os.path.basename(h_pb).replace(pb_extension, ''):
|
||||
matched_host = h_pb
|
||||
for group in inv.groups_for_host(host):
|
||||
if matched_group:
|
||||
break
|
||||
for g_pb in group_playbooks:
|
||||
if group.name == os.path.basename(g_pb).replace(pb_extension, ''):
|
||||
matched_group = g_pb
|
||||
|
||||
if matched_host and matched_group:
|
||||
print "\nError: Found a group playbook and a host playbook for %s" % host
|
||||
continue
|
||||
|
||||
if not matched_host and not matched_group:
|
||||
print "\nNo playbook found for %s" % host
|
||||
continue
|
||||
|
||||
if matched_group:
|
||||
print "\nplaybook is %s" % matched_group
|
||||
print "Run with: \n ansible-playbook %s --limit=%s\n" % (matched_group, host)
|
||||
|
||||
if matched_host:
|
||||
print "\nplaybook is %s" % matched_host
|
||||
print "Run with: \n ansible-playbook %s" % (matched_host)
|
||||
|
||||
|
||||
|
||||
print ''
|
||||
return 0
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
Loading…
Add table
Add a link
Reference in a new issue