-
-
Save eumel8/c391554596885ad5892ac8c83d4f64bd to your computer and use it in GitHub Desktop.
ansible inventory module that lists lxd containers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import sys | |
import subprocess | |
import re | |
def containers(): | |
lxcOutput = subprocess.check_output( ['lxc', 'list' ] ) | |
ips = re.compile( '\d+\.\d+\.\d+\.\d+' ).findall( str( lxcOutput ) ) | |
nodes = dict( hosts = ips, vars = { "ansible_user": "root" } ) | |
inventory = dict( nodes = nodes ) | |
return inventory | |
import argparse | |
import json | |
parser = argparse.ArgumentParser() | |
parser.add_argument( '--list', action = 'store_true' ) | |
parser.add_argument( '--host' ) | |
arguments = parser.parse_args() | |
if arguments.list: | |
json.dump( containers(), sys.stdout ) | |
if arguments.host: | |
json.dump( {}, sys.stdout ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment