Commit 5d4cab06 authored by Noe Nieto's avatar Noe Nieto 💬

Ansible command works now

parent 546e6996
......@@ -23,10 +23,25 @@ Vagrant.configure("2") do |config|
libvirt.graphics_type = "spice"
libvirt.cpus = {cpus}
end
{hostname}.vm.provision "ansible" do |ansible|
ansible.playbook = "shim.yml"
end
end
end
"""
ansible_shim = """
---
- hosts: all
become: yes
tasks:
- name: Shim file for ansible
file:
path: /etc/shipyard_shim.txt
state: touch
"""
XDG_CONFIG_HOME = Path(os.environ['HOME'],'.config','ldh_developer','shipyard')
......@@ -101,6 +116,8 @@ def create_box(hostname, ram, cpus):
ram=ram,
cpus=cpus,
))
# The Ansible shim
vagrant_wd.joinpath('shim.tml').open(mode='w').write(ansible_shim)
# Execute vagrant with the generated vagrantfile
subprocess.run(['vagrant','up'], cwd=vagrant_wd)
......@@ -120,10 +137,16 @@ def destroy_vm(hostname):
@only_if_box_exist
def run_playbook(hostname, playbook):
"""
run a playbook against one of the boxes
run an Ansible playbook against this vm
"""
vagrant_wd = XDG_CONFIG_HOME.joinpath(hostname)
subprocess.run(['vagrant','destroy'], cwd=vagrant_wd)
inventory_file = vagrant_wd.joinpath('.vagrant', 'provisioners', 'ansible', 'inventory', 'vagrant_ansible_inventory')
subprocess.run([
'ansible-playbook', '-u', 'vagrant', '-i', f'{inventory_file}',
f'{Path(playbook).resolve()}'
],
cwd=vagrant_wd
)
@only_if_box_exist
......@@ -209,7 +232,8 @@ if __name__ == '__main__':
sub_parser.add_argument('hostname', help='This is the hostname of the box')
if cmd_args.command == 'playbook':
sub_parser.add_argument('--playbook', help='Path to the yml file', required=True)
sub_parser.usage = 'shipyard playbook hostname path/to/playbook.yml'
sub_parser.add_argument('playbook', help='The path to the playbook file')
sub_args = sub_parser.parse_args(sys.argv[2:])
run_playbook(sub_args.hostname, sub_args.playbook)
sys.exit()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment