Skip to content
Snippets Groups Projects
Commit b636ab31 authored by Thomas Woerner's avatar Thomas Woerner
Browse files

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.
parent ff08ee7e
Branches
Tags
No related merge requests found
...@@ -201,9 +201,19 @@ def parse_options(): ...@@ -201,9 +201,19 @@ def parse_options():
choices=("yes", "no"), default=None, choices=("yes", "no"), default=None,
help="The bool value defines if the needed packages " help="The bool value defines if the needed packages "
"are installed on the node. Default: yes") "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() 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: if options.password_prompt:
parser.error("password prompt is not possible with ansible") parser.error("password prompt is not possible with ansible")
if options.log_file: if options.log_file:
...@@ -240,10 +250,14 @@ def run_cmd(args): ...@@ -240,10 +250,14 @@ def run_cmd(args):
def main(options, 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") inventory = os.path.join(playbook_dir, "ipaclient-inventory")
playbook = os.path.join(temp_dir, "client-playbook.yml") playbook = os.path.join(playbook_dir, "ipaclient-playbook.yml")
with open(inventory, 'w') as f: with open(inventory, 'w') as f:
if options.servers: if options.servers:
...@@ -356,6 +370,7 @@ def main(options, args): ...@@ -356,6 +370,7 @@ def main(options, args):
if returncode != 0: if returncode != 0:
raise RuntimeError() raise RuntimeError()
finally: finally:
if not options.playbook_dir:
shutil.rmtree(temp_dir, ignore_errors=True) shutil.rmtree(temp_dir, ignore_errors=True)
......
...@@ -271,9 +271,19 @@ def parse_options(): ...@@ -271,9 +271,19 @@ def parse_options():
help="The value defines if the needed services will " help="The value defines if the needed services will "
"automatically be openen in the firewall managed by " "automatically be openen in the firewall managed by "
"firewalld. Default: yes") "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() 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: if options.log_file:
parser.error("log_file is not supported") parser.error("log_file is not supported")
...@@ -308,10 +318,14 @@ def run_cmd(args): ...@@ -308,10 +318,14 @@ def run_cmd(args):
def main(options, 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") inventory = os.path.join(playbook_dir, "ipareplica-inventory")
playbook = os.path.join(temp_dir, "replica-playbook.yml") playbook = os.path.join(playbook_dir, "ipareplica-playbook.yml")
with open(inventory, 'w') as f: with open(inventory, 'w') as f:
if options.servers: if options.servers:
...@@ -472,6 +486,7 @@ def main(options, args): ...@@ -472,6 +486,7 @@ def main(options, args):
if returncode != 0: if returncode != 0:
raise RuntimeError() raise RuntimeError()
finally: finally:
if not options.playbook_dir:
shutil.rmtree(temp_dir, ignore_errors=True) shutil.rmtree(temp_dir, ignore_errors=True)
......
...@@ -307,9 +307,19 @@ def parse_options(): ...@@ -307,9 +307,19 @@ def parse_options():
choices=("yes", "no"), default=None, choices=("yes", "no"), default=None,
help="Copy the generated CSR from the ipaserver to " help="Copy the generated CSR from the ipaserver to "
"the controller as <hostname>-ipa.csr.") "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() 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: if options.log_file:
parser.error("log_file is not supported") parser.error("log_file is not supported")
...@@ -344,10 +354,14 @@ def run_cmd(args): ...@@ -344,10 +354,14 @@ def run_cmd(args):
def main(options, 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") inventory = os.path.join(playbook_dir, "ipaserver-inventory")
playbook = os.path.join(temp_dir, "server-playbook.yml") playbook = os.path.join(playbook_dir, "ipaserver-playbook.yml")
with open(inventory, 'w') as f: with open(inventory, 'w') as f:
f.write("[ipaserver]\n") f.write("[ipaserver]\n")
...@@ -529,6 +543,7 @@ def main(options, args): ...@@ -529,6 +543,7 @@ def main(options, args):
if returncode != 0: if returncode != 0:
raise RuntimeError() raise RuntimeError()
finally: finally:
if not options.playbook_dir:
shutil.rmtree(temp_dir, ignore_errors=True) shutil.rmtree(temp_dir, ignore_errors=True)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment