Skip to content

Commit 20bbbfb

Browse files
committed
[#43121095] Add puppet.loadhosts task
Loads hosts that use given Puppet class(es). This differs from the `class` task which only returns nodes of a given "role". It uses the functionality added to `govuk_node_list` in: https://github.gds/gds/puppet/commit/d986313df235af0ac225f8e7f3e5838574a3dec0 For example, to run a command on machines that include the `redis` and `govuk::apps::govuk_crawler_worker` hosts. Note there is `logs-redis-N` in addition to `redis-N`: (fabric)➜ fabric-scripts git:(puppet_loadhosts_by_classes) fab --hide=running,status preview puppet.loadhosts:redis,govuk::apps::govuk_crawler_worker hosts logs-redis-1.management.production logs-redis-2.management.production mirrorer-1.management.production redis-1.backend.production redis-2.backend.production
1 parent 3831dba commit 20bbbfb

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

puppet.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
from fabric.api import *
22

3+
@task
4+
def loadhosts(*classnames):
5+
"""Load hosts that include given Puppet class(es)"""
6+
classnames = ','.join(classnames)
7+
with hide('running', 'stdout'):
8+
with settings(host_string=env.gateway, gateway=None):
9+
env.hosts = run('govuk_node_list -C %s' % classnames).splitlines()
10+
311
def puppet(*args):
412
sudo('govuk_puppet %s' % ' '.join(args))
513

0 commit comments

Comments
 (0)