mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Merge pull request #11294 from msabramo/serf_plugin_use_env_vars
plugins/inventory/serf.py: Use SERF_RPC_* env vars
This commit is contained in:
commit
888f3236c5
1 changed files with 25 additions and 4 deletions
|
@ -20,10 +20,18 @@
|
|||
# Dynamic inventory script which lets you use nodes discovered by Serf
|
||||
# (https://serfdom.io/).
|
||||
#
|
||||
# Requires host to be a member of a Serf cluster and the `serfclient` Python
|
||||
# module from https://pypi.python.org/pypi/serfclient
|
||||
# Requires the `serfclient` Python module from
|
||||
# https://pypi.python.org/pypi/serfclient
|
||||
#
|
||||
# Environment variables
|
||||
# ---------------------
|
||||
# - `SERF_RPC_ADDR`
|
||||
# - `SERF_RPC_AUTH`
|
||||
#
|
||||
# These variables are described at https://www.serfdom.io/docs/commands/members.html#_rpc_addr
|
||||
|
||||
import argparse
|
||||
import os
|
||||
import sys
|
||||
|
||||
# https://pypi.python.org/pypi/serfclient
|
||||
|
@ -37,9 +45,22 @@ except ImportError:
|
|||
_key = 'serf'
|
||||
|
||||
|
||||
def _serf_client():
|
||||
kwargs = {}
|
||||
|
||||
rpc_addr = os.getenv('SERF_RPC_ADDR')
|
||||
if rpc_addr:
|
||||
kwargs['host'], kwargs['port'] = rpc_addr.split(':')
|
||||
|
||||
rpc_auth = os.getenv('SERF_RPC_AUTH')
|
||||
if rpc_auth:
|
||||
kwargs['rpc_auth'] = rpc_auth
|
||||
|
||||
return SerfClient(**kwargs)
|
||||
|
||||
|
||||
def get_serf_members_data():
|
||||
serf = SerfClient()
|
||||
return serf.members().body['Members']
|
||||
return _serf_client().members().body['Members']
|
||||
|
||||
|
||||
def get_nodes(data):
|
||||
|
|
Loading…
Reference in a new issue