diff --git a/collections/requirements.yml b/collections/requirements.yml deleted file mode 100644 index 9c1858c..0000000 --- a/collections/requirements.yml +++ /dev/null @@ -1,3 +0,0 @@ -collections: - # Installs the latest version from Ansible Galaxy - - name: ansible.windows \ No newline at end of file diff --git a/inventories/production/group_vars/domain_controllers.yml b/inventories/production/group_vars/domain_controllers.yml new file mode 100644 index 0000000..73b9d16 --- /dev/null +++ b/inventories/production/group_vars/domain_controllers.yml @@ -0,0 +1,7 @@ +--- +ansible_connection: winrm +ansible_port: 5986 +ansible_winrm_transport: ntlm +ansible_winrm_scheme: https +ansible_winrm_server_cert_validation: ignore +ansible_winrm_kinit_mode: managed diff --git a/inventories/production/group_vars/windows.yml b/inventories/production/group_vars/windows.yml new file mode 100644 index 0000000..7e61b98 --- /dev/null +++ b/inventories/production/group_vars/windows.yml @@ -0,0 +1,8 @@ +--- +ansible_connection: winrm +ansible_port: 5986 +#ansible_winrm_transport: kerberos +ansible_winrm_transport: ntlm +ansible_winrm_scheme: https +ansible_winrm_server_cert_validation: ignore +ansible_winrm_kinit_mode: managed diff --git a/inventory/prod/linux.yml b/inventories/production/linux.yml similarity index 57% rename from inventory/prod/linux.yml rename to inventories/production/linux.yml index 1db3a12..525ee52 100644 --- a/inventory/prod/linux.yml +++ b/inventories/production/linux.yml @@ -5,4 +5,6 @@ all: web01.internal.codetical.com: pelican.internal.codetical.com: pinas.internal.codetical.com: - pirateship.internal.codetical.com: \ No newline at end of file + pirateship.internal.codetical.com: + cloud.internal.codetical.com: + dev01.internal.codetical.com: diff --git a/inventories/production/windows.yml b/inventories/production/windows.yml new file mode 100644 index 0000000..7720849 --- /dev/null +++ b/inventories/production/windows.yml @@ -0,0 +1,12 @@ +all: + children: + domain_controllers: + hosts: + dc01.internal.codetical.com: + windows: + hosts: + dc02.internal.codetical.com: + win_all: + children: + domain_controllers: + windows: \ No newline at end of file diff --git a/inventory/prod/windows.yml b/inventory/prod/windows.yml deleted file mode 100644 index 19184c1..0000000 --- a/inventory/prod/windows.yml +++ /dev/null @@ -1,29 +0,0 @@ -all: - children: - domain_controllers: - hosts: - dc01.internal.codetical.com: - vars: - ansible_connection: winrm - ansible_port: 5986 - #ansible_winrm_transport: kerberos - ansible_winrm_transport: ntlm - ansible_winrm_scheme: https - ansible_winrm_server_cert_validation: ignore - ansible_winrm_kinit_mode: managed - windows: - hosts: - dc02.internal.codetical.com: - backup.internal.codetical.com: - vars: - ansible_connection: winrm - ansible_port: 5986 - #ansible_winrm_transport: kerberos - ansible_winrm_transport: ntlm - ansible_winrm_scheme: https - ansible_winrm_server_cert_validation: ignore - ansible_winrm_kinit_mode: managed - win_all: - children: - domain_controllers: - windows: \ No newline at end of file diff --git a/playbook_windows_update.yaml b/playbook_windows_update.yaml deleted file mode 100644 index 93bf989..0000000 --- a/playbook_windows_update.yaml +++ /dev/null @@ -1,31 +0,0 @@ -- name: Apply Windows Updates - hosts: win_all - gather_facts: yes - vars: - initial_reboot: |- - {{ 86400 < - (( ((ansible_date_time.date+" "+ansible_date_time.time)|to_datetime('%Y-%m-%d %H:%M:%S')) - - ansible_facts.lastboot|to_datetime('%Y-%m-%d %H:%M:%SZ')).total_seconds())|abs }} - tasks: - - block: - - name: Install Updates And Reboot - ansible.windows.win_updates: - category_names: - - SecurityUpdates - - CriticalUpdates - - UpdateRollups - - DefinitionUpdates - - Updates - reboot: false - state: installed - become: yes - become_method: runas - become_user: SYSTEM - register: update_results - - - name: Reboot explicitly if required - ansible.windows.win_reboot: - reboot_timeout: 3600 - post_reboot_delay: 120 - test_command: 'powershell.exe -Command "Get-Service WinRM"' - when: update_results.reboot_required \ No newline at end of file diff --git a/playbooks/all_ping.yaml b/playbooks/all_ping.yaml new file mode 100644 index 0000000..8c8d21e --- /dev/null +++ b/playbooks/all_ping.yaml @@ -0,0 +1,14 @@ +--- +- name: All Servers Test Windows Connectivity And Output Facts + hosts: all + gather_facts: true + tasks: + - name: Ping The Windows Hosts + ansible.windows.win_ping: + - name: Export Facts + ansible.builtin.copy: + mode: "0644" + content: "{{ ansible_facts | to_nice_json }}" + dest: "{{ playbook_dir }}../facts/{{ inventory_hostname }}.json" + delegate_to: localhost + tags: ["never", "debug"] diff --git a/playbook_update_linux.yaml b/playbooks/playbook_update_linux.yaml similarity index 96% rename from playbook_update_linux.yaml rename to playbooks/playbook_update_linux.yaml index 0bf3c49..e1e2c50 100644 --- a/playbook_update_linux.yaml +++ b/playbooks/playbook_update_linux.yaml @@ -13,7 +13,7 @@ - name: Upgrade all packages (RHEL/CentOS/Rocky) ansible.builtin.dnf: name: "*" - state: latest + state: present when: ansible_facts["os_family"] == "RedHat" become: true @@ -29,7 +29,7 @@ msg: "Reboot initiated by Ansible due to system updates" connect_timeout: 5 reboot_timeout: 300 - when: + when: - ansible_facts["os_family"] == "Debian" - reboot_required_file.stat.exists become: true diff --git a/playbooks/playbook_windows_update.yaml b/playbooks/playbook_windows_update.yaml new file mode 100644 index 0000000..b9530f2 --- /dev/null +++ b/playbooks/playbook_windows_update.yaml @@ -0,0 +1,29 @@ +--- +- name: Apply Windows Updates + hosts: win_all + gather_facts: true + vars: + initial_reboot: |- + {{ 86400 < + (( ((ansible_date_time.date+" "+ansible_date_time.time)|to_datetime('%Y-%m-%d %H:%M:%S')) - + ansible_facts.lastboot|to_datetime('%Y-%m-%d %H:%M:%SZ')).total_seconds())|abs }} + tasks: + - name: Run Windows Updates + block: + - name: Install Updates And Reboot + ansible.windows.win_updates: + category_names: + - "*" + reboot: false + state: installed + become: true + become_method: ansible.builtin.runas + become_user: SYSTEM + register: update_results + + - name: Reboot explicitly if required + ansible.windows.win_reboot: + reboot_timeout: 3600 + post_reboot_delay: 120 + test_command: 'powershell.exe -Command "Get-Service WinRM"' + when: update_results.reboot_required diff --git a/requirements.yml b/requirements.yml new file mode 100644 index 0000000..320bae4 --- /dev/null +++ b/requirements.yml @@ -0,0 +1,7 @@ +--- +collections: + - name: ansible.windows + - name: community.general +roles: + - name: manala.apt + src: manala.apt diff --git a/roles/requirements.yml b/roles/requirements.yml deleted file mode 100644 index 0e84217..0000000 --- a/roles/requirements.yml +++ /dev/null @@ -1,3 +0,0 @@ -roles: - - name: manala.apt - src: manala.apt \ No newline at end of file