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.
This commit is contained in:
Thomas Woerner
2019-08-06 12:42:21 +02:00
parent d43b4429e6
commit 1d5b5d38b7
3 changed files with 50 additions and 29 deletions

View File

@@ -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])

View File

@@ -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])

View File

@@ -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])