utils/ansible-ipa-[server,replica,client]-install: New --playbook-dir option

If the --playbook-dir option is used, the inventory and playbook files will
be generated in this directory. The files will not be removed after the
playbook processing ended.

If the directory does not exist an error message will be printed and the
utility will not continue.
This commit is contained in:
Thomas Woerner
2019-08-06 09:17:59 +02:00
parent ff08ee7ee6
commit b636ab3112
3 changed files with 57 additions and 12 deletions

View File

@@ -201,9 +201,19 @@ def parse_options():
choices=("yes", "no"), default=None,
help="The bool value defines if the needed packages "
"are installed on the node. Default: yes")
# playbook
parser.add_argument("--playbook-dir",
dest="playbook_dir",
default=None,
help="If defined will be used as to create inventory "
"file and playbook in. The files will not be removed "
"after the playbook processing ended.")
options, args = parser.parse_known_args()
if options.playbook_dir and not os.path.isdir(options.playbook_dir):
parser.error("playbook dir does not exist")
if options.password_prompt:
parser.error("password prompt is not possible with ansible")
if options.log_file:
@@ -240,10 +250,14 @@ def run_cmd(args):
def main(options, args):
temp_dir = tempfile.mkdtemp(prefix='ansible-ipa')
if options.playbook_dir:
playbook_dir = options.playbook_dir
else:
temp_dir = tempfile.mkdtemp(prefix='ansible-ipa-client')
playbook_dir = temp_dir
inventory = os.path.join(temp_dir, "client-inventory")
playbook = os.path.join(temp_dir, "client-playbook.yml")
inventory = os.path.join(playbook_dir, "ipaclient-inventory")
playbook = os.path.join(playbook_dir, "ipaclient-playbook.yml")
with open(inventory, 'w') as f:
if options.servers:
@@ -356,7 +370,8 @@ def main(options, args):
if returncode != 0:
raise RuntimeError()
finally:
shutil.rmtree(temp_dir, ignore_errors=True)
if not options.playbook_dir:
shutil.rmtree(temp_dir, ignore_errors=True)
options, args = parse_options()

View File

@@ -271,9 +271,19 @@ def parse_options():
help="The value defines if the needed services will "
"automatically be openen in the firewall managed by "
"firewalld. Default: yes")
# playbook
parser.add_argument("--playbook-dir",
dest="playbook_dir",
default=None,
help="If defined will be used as to create inventory "
"file and playbook in. The files will not be removed "
"after the playbook processing ended.")
options, args = parser.parse_known_args()
if options.playbook_dir and not os.path.isdir(options.playbook_dir):
parser.error("playbook dir does not exist")
if options.log_file:
parser.error("log_file is not supported")
@@ -308,10 +318,14 @@ def run_cmd(args):
def main(options, args):
temp_dir = tempfile.mkdtemp(prefix='ansible-ipa')
if options.playbook_dir:
playbook_dir = options.playbook_dir
else:
temp_dir = tempfile.mkdtemp(prefix='ansible-ipa-replica')
playbook_dir = temp_dir
inventory = os.path.join(temp_dir, "replica-inventory")
playbook = os.path.join(temp_dir, "replica-playbook.yml")
inventory = os.path.join(playbook_dir, "ipareplica-inventory")
playbook = os.path.join(playbook_dir, "ipareplica-playbook.yml")
with open(inventory, 'w') as f:
if options.servers:
@@ -472,7 +486,8 @@ def main(options, args):
if returncode != 0:
raise RuntimeError()
finally:
shutil.rmtree(temp_dir, ignore_errors=True)
if not options.playbook_dir:
shutil.rmtree(temp_dir, ignore_errors=True)
options, args = parse_options()

View File

@@ -307,9 +307,19 @@ def parse_options():
choices=("yes", "no"), default=None,
help="Copy the generated CSR from the ipaserver to "
"the controller as <hostname>-ipa.csr.")
# playbook
parser.add_argument("--playbook-dir",
dest="playbook_dir",
default=None,
help="If defined will be used as to create inventory "
"file and playbook in. The files will not be removed "
"after the playbook processing ended.")
options, args = parser.parse_known_args()
if options.playbook_dir and not os.path.isdir(options.playbook_dir):
parser.error("playbook dir does not exist")
if options.log_file:
parser.error("log_file is not supported")
@@ -344,10 +354,14 @@ def run_cmd(args):
def main(options, args):
temp_dir = tempfile.mkdtemp(prefix='ansible-ipa')
if options.playbook_dir:
playbook_dir = options.playbook_dir
else:
temp_dir = tempfile.mkdtemp(prefix='ansible-ipa-server')
playbook_dir = temp_dir
inventory = os.path.join(temp_dir, "server-inventory")
playbook = os.path.join(temp_dir, "server-playbook.yml")
inventory = os.path.join(playbook_dir, "ipaserver-inventory")
playbook = os.path.join(playbook_dir, "ipaserver-playbook.yml")
with open(inventory, 'w') as f:
f.write("[ipaserver]\n")
@@ -529,7 +543,8 @@ def main(options, args):
if returncode != 0:
raise RuntimeError()
finally:
shutil.rmtree(temp_dir, ignore_errors=True)
if not options.playbook_dir:
shutil.rmtree(temp_dir, ignore_errors=True)
options, args = parse_options()