From 1d5b5d38b76d88915b6c81a0fd8f22b8d18432e4 Mon Sep 17 00:00:00 2001 From: Thomas Woerner Date: Tue, 6 Aug 2019 12:42:21 +0200 Subject: [PATCH] utils/ansible-ipa-[server,replica,client]-install: New --become-method option This option is the same as the --become-method option with ansible-playbook. If this option is set, become_method will be set in the generated playbook. --- utils/ansible-ipa-client-install | 25 ++++++++++++++++--------- utils/ansible-ipa-replica-install | 29 ++++++++++++++++++----------- utils/ansible-ipa-server-install | 25 ++++++++++++++++--------- 3 files changed, 50 insertions(+), 29 deletions(-) diff --git a/utils/ansible-ipa-client-install b/utils/ansible-ipa-client-install index 64f29742..373d29f3 100755 --- a/utils/ansible-ipa-client-install +++ b/utils/ansible-ipa-client-install @@ -208,6 +208,12 @@ def parse_options(): 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.") + parser.add_argument("--become-method", + dest="become_method", + default="sudo", + help="privilege escalation method to use " + "(default=sudo), use `ansible-doc -t become -l` to " + "list valid choices.") options, args = parser.parse_known_args() @@ -356,15 +362,16 @@ def main(options, args): state = "present" with open(playbook, 'w') as f: - f.write("""--- -- name: Playbook to configure IPA clients - hosts: ipaclients - become: true - - roles: - - role: ipaclient - state: %s -""" % state) + f.write("---\n") + f.write("- name: Playbook to configure IPA clients\n") + f.write(" hosts: ipaclients\n") + f.write(" become: true\n") + if options.become_method: + f.write(" become_method: %s\n" % options.become_method) + f.write("\n") + f.write(" roles:\n") + f.write(" - role: ipaclient\n") + f.write(" state: %s\n" % state) try: returncode = run_cmd(['ansible-playbook', '-i', inventory, playbook]) diff --git a/utils/ansible-ipa-replica-install b/utils/ansible-ipa-replica-install index 3c9f7328..68cbead6 100755 --- a/utils/ansible-ipa-replica-install +++ b/utils/ansible-ipa-replica-install @@ -278,6 +278,12 @@ def parse_options(): 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.") + parser.add_argument("--become-method", + dest="become_method", + default="sudo", + help="privilege escalation method to use " + "(default=sudo), use `ansible-doc -t become -l` to " + "list valid choices.") options, args = parser.parse_known_args() @@ -334,10 +340,10 @@ def main(options, args): for server in options.servers: f.write("%s\n" % server) f.write("\n") - f.write("[ipareplica]\n") + f.write("[ipareplicas]\n") f.write("%s\n" % args[0]) f.write("\n") - f.write("[ipareplica:vars]\n") + f.write("[ipareplicas:vars]\n") # basic if options.admin_password: f.write("ipaadmin_password=%s\n" % options.admin_password) @@ -472,15 +478,16 @@ def main(options, args): state = "present" with open(playbook, 'w') as f: - f.write("""--- -- name: Playbook to configure IPA replica - hosts: ipareplica - become: true - - roles: - - role: ipareplica - state: %s -""" % state) + f.write("---\n") + f.write("- name: Playbook to configure IPA replicas\n") + f.write(" hosts: ipareplicas\n") + f.write(" become: true\n") + if options.become_method: + f.write(" become_method: %s\n" % options.become_method) + f.write("\n") + f.write(" roles:\n") + f.write(" - role: ipareplica\n") + f.write(" state: %s\n" % state) try: returncode = run_cmd(['ansible-playbook', '-i', inventory, playbook]) diff --git a/utils/ansible-ipa-server-install b/utils/ansible-ipa-server-install index 65a9afc2..3faf480c 100755 --- a/utils/ansible-ipa-server-install +++ b/utils/ansible-ipa-server-install @@ -314,6 +314,12 @@ def parse_options(): 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.") + parser.add_argument("--become-method", + dest="become_method", + default="sudo", + help="privilege escalation method to use " + "(default=sudo), use `ansible-doc -t become -l` to " + "list valid choices.") options, args = parser.parse_known_args() @@ -529,15 +535,16 @@ def main(options, args): state = "present" with open(playbook, 'w') as f: - f.write("""--- -- name: Playbook to configure IPA server - hosts: ipaserver - become: true - - roles: - - role: ipaserver - state: %s -""" % state) + f.write("---\n") + f.write("- name: Playbook to configure IPA server\n") + f.write(" hosts: ipaserver\n") + f.write(" become: true\n") + if options.become_method: + f.write(" become_method: %s\n" % options.become_method) + f.write("\n") + f.write(" roles:\n") + f.write(" - role: ipaserver\n") + f.write(" state: %s\n" % state) try: returncode = run_cmd(['ansible-playbook', '-i', inventory, playbook]) -- GitLab