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