diff --git a/modules/vagrant_generator.py b/modules/vagrant_generator.py index 1bb4dfd2a93cff197de219feb12473a1167d4517..2570b081b32a72bbc6e18e7ddd9d2b2a21bf9c37 100644 --- a/modules/vagrant_generator.py +++ b/modules/vagrant_generator.py @@ -99,6 +99,7 @@ def _create_commands(device_attributes): def _create_ansible_commands(device_name, playbook_location, input_definitions, flags): """Create commands for running a playbook from the Vagrantfile.""" commands = [] + windows_hosts = _find_windows_boxes(input_definitions); playbook = dict() playbook["type"] = "string" @@ -130,6 +131,8 @@ def _create_ansible_commands(device_name, playbook_location, input_definitions, for router in input_definitions["routers"]: router_names.append(router["name"]) groups["groups"]["routers"] = router_names + windows_hosts = _find_windows_boxes(input_definitions) + groups["groups"]["windows"] = windows_hosts if "groups" in input_definitions: for group in input_definitions["groups"]: groups["groups"][group["name"]] = group["nodes"] @@ -157,8 +160,14 @@ def _create_ansible_commands(device_name, playbook_location, input_definitions, extravars["type"] = "dictionary" extravars["command"] = "extra_vars" extravars["dictionary"] = dict() - extravars["dictionary"]["ansible_python_interpreter"] = \ - "\"/usr/bin/python3\"" + if device_name in windows_hosts: + extravars["dictionary"]["ansible_connection"] = "\"winrm\"" + extravars["dictionary"]["ansible_user"] = "\"vagrant\"" + extravars["dictionary"]["ansible_password"] = "\"vagrant\"" + extravars["dictionary"]["ansible_winrm_transport"] = "\"basic\"" + extravars["dictionary"]["ansible_winrm_server_cert_validation"] = "\"ignore\"" + else: + extravars["dictionary"]["ansible_python_interpreter"] = "\"/usr/bin/python3\"" commands.append(extravars) return commands diff --git a/templates/controller b/templates/controller index 272ee14f561b8d9e8da475e3212ac3a6ae4ab95b..8351a03292d43cd27bb35abdb98960876166ce61 100644 --- a/templates/controller +++ b/templates/controller @@ -19,18 +19,9 @@ loop_control: loop_var: interface -- name: Prepare controller - hosts: controller - become: yes - tasks: - - name: Install pywinrm - pip: - name: pywinrm - executable: "/usr/bin/pip3" - - - name: Add aliases - lineinfile: - path: /etc/hosts - line: '192.168.20.6 win' -... \ No newline at end of file +- name: Install pywinrm + pip: + name: pywinrm + executable: "/usr/bin/pip3" +... diff --git a/templates/device_configuration b/templates/device_configuration index 515b12bd0bad4c6f12f3d271df801f2e0b9d1b6e..1e103ef7a98d0effefb1508d17fa7c968d082d04 100644 --- a/templates/device_configuration +++ b/templates/device_configuration @@ -19,9 +19,21 @@ name: routers when: config.routers -- name: Configuring devices separately - hosts: all +- name: Configuring Linux devices separately + hosts: all:!windows + become: yes + tasks: + - name: include role + include_role: + name: "{{ inventory_hostname }}" + +- name: Configuring Windows devices separately + hosts: windows become: yes + become_method: runas + become_user: vagrant + vars: + ansible_become_pass: vagrant tasks: - name: include role include_role: diff --git a/templates/separate_devices b/templates/separate_devices index a29c0714196e58577b3c4d73093c0cfd76c05442..88b2ca7c7f2fdc18e2a14ab4bc11414bc9c54df5 100644 --- a/templates/separate_devices +++ b/templates/separate_devices @@ -22,4 +22,4 @@ loop: "{{ routes }}" loop_control: loop_var: interface -... \ No newline at end of file +... diff --git a/templates/windows_devices b/templates/windows_devices index 1c57881d8451ce8379310271924e029d22e992c0..bf9673bbaad95198a2275c17c42258ef7dd50980 100644 --- a/templates/windows_devices +++ b/templates/windows_devices @@ -1,10 +1,6 @@ --- -- name: Hello world - hosts: all - tasks: - - name: print hello world - debug: - msg: "Hello World" - -... \ No newline at end of file +- name: print hello world + debug: + msg: "Hello World" +...