fixes to do multimachine run_playbook
parent
d5776757d3
commit
c1c60bb233
|
@ -3,29 +3,38 @@
|
|||
from __future__ import print_function
|
||||
import sh
|
||||
import argparse
|
||||
import vagrant
|
||||
|
||||
# compute: inventory, private key, user and pass along all the other parameters to ansible-playbook
|
||||
|
||||
parser = argparse.ArgumentParser(description='Run the ansible playbook, using vagrant ssh-config parameters')
|
||||
|
||||
#parser.add_argument('node', metavar='n', type=str, nargs='?',
|
||||
# help='node to run playbook on')
|
||||
|
||||
parser.add_argument('node', metavar='n', type=str, nargs='?',
|
||||
help='node to run playbook on')
|
||||
parser.add_argument('playbook_path', metavar='f', type=str, nargs='?',
|
||||
help='path for the ansible playbook')
|
||||
|
||||
(args, unknown) = parser.parse_known_args()
|
||||
print (args.node, args.playbook_path)
|
||||
|
||||
# for now if not multimachine, ignore node parameter
|
||||
v = vagrant.Vagrant()
|
||||
|
||||
if len(v.status()) > 1:
|
||||
multimachine = True
|
||||
private_key = v.keyfile(args.node)
|
||||
user = v.user(args.node)
|
||||
else:
|
||||
multimachine = False
|
||||
private_key = v.keyfile()
|
||||
user = v.user()
|
||||
|
||||
ssh_config = dict([s.strip().split(" ") for s in str(sh.vagrant("ssh-config")).strip().split("\n")])
|
||||
params = ["=".join(p) for p in (
|
||||
("--private-key", ssh_config.get("IdentityFile")),
|
||||
("--user", ssh_config.get("User")),
|
||||
("--private-key", private_key),
|
||||
("--user", user),
|
||||
("--inventory-file",".vagrant/provisioners/ansible/inventory/vagrant_ansible_inventory")
|
||||
)] + unknown + [args.playbook_path]
|
||||
|
||||
# call ansible-playbook with
|
||||
|
||||
|
||||
for line in sh.ansible_playbook(*params, _cwd=".", _iter=True):
|
||||
print(line, end="")
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
- name: unglueit setup
|
||||
hosts: unglueit
|
||||
hosts: please
|
||||
vars:
|
||||
user: "{{ ansible_ssh_user }}"
|
||||
sudo: yes
|
||||
|
|
Loading…
Reference in New Issue