====== Windows szerver kezelése Ansible programmal ====== ===== Távoli elérés (opcionális) ===== Adminisztrátorként futtatott PowerShell parancssorban adjuk ki az alábbi utasításokat a TerminalServer szolgáltatás bekapcsolásához. === Szolgáltatás engedélyezése === PS C:\Users\Administrator> Set-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server' -name 'fDenyTSConnections' -Value 0 PS C:\Users\Administrator> Get-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server' -name 'fDenyTSConnections' fDenyTSConnections : 0 PSPath : Microsoft.PowerShell.Core\Registry::HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal S erver PSParentPath : Microsoft.PowerShell.Core\Registry::HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control PSChildName : Terminal Server PSDrive : HKLM PSProvider : Microsoft.PowerShell.Core\Registry === Tűzfal szabályok módosítása === PS C:\Users\Administrator> Enable-NetFirewallRule -DisplayGroup "Remote Desktop" === Szolgáltatás ellenőrzése === PS C:\Users\Administrator> Get-Service TermService Status Name DisplayName ------ ---- ----------- Running TermService Remote Desktop Services ===== WinRM szolgáltatás ===== Adminisztrátorként futtatott PowerShell parancssorban adjuk ki az alábbi utasításokat a WinRM szolgáltatás bekapcsolásához. === Szolgáltatás konfigurálása === PS C:\Users\Administrator> winrm quickconfig === Szolgáltatás engedélyezése és ellenőrzése === PS C:\Users\Administrator> Enable-PSRemoting -Force PS C:\Users\Administrator> Get-Service WinRM Status Name DisplayName ------ ---- ----------- Running WinRM Windows Remote Management (WS-Manag... PS C:\Users\Administrator> Get-Service WinRM | Select-Object StartType StartType --------- Automatic PS C:\Users\Administrator> winrm enumerate winrm/config/listener Listener Address = * Transport = HTTP Port = 5985 Hostname Enabled = true URLPrefix = wsman CertificateThumbprint ListeningOn = 127.0.0.1, 192.168.110.51, ::1, fe80::317d:e4ae:1de6:e99c%4 PS C:\Users\Administrator> Test-WSMan wsmid : http://schemas.dmtf.org/wbem/wsman/identity/1/wsmanidentity.xsd ProtocolVersion : http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd ProductVendor : Microsoft Corporation ProductVersion : OS: 0.0.0 SP: 0.0 Stack: 3.0 PS C:\Users\Administrator> winrm get winrm/config/service Service RootSDDL = O:NSG:BAD:P(A;;GA;;;BA)(A;;GR;;;IU)S:P(AU;FA;GA;;;WD)(AU;SA;GXGW;;;WD) MaxConcurrentOperations = 4294967295 MaxConcurrentOperationsPerUser = 1500 EnumerationTimeoutms = 240000 MaxConnections = 300 MaxPacketRetrievalTimeSeconds = 120 AllowUnencrypted = false Auth Basic = false Kerberos = true Negotiate = true Certificate = false CredSSP = false CbtHardeningLevel = Relaxed DefaultPorts HTTP = 5985 HTTPS = 5986 IPv4Filter = * IPv6Filter = * EnableCompatibilityHttpListener = false EnableCompatibilityHttpsListener = false CertificateThumbprint AllowRemoteAccess = true === Hitelesítési eljárás beállítása === PS C:\Users\Administrator> winrm set winrm/config/service/auth '@{Basic="false";Kerberos="true";Negotiate="true"}' Auth Basic = false Kerberos = true Negotiate = true Certificate = false CredSSP = false CbtHardeningLevel = Relaxed === Tűzfal szabályrendszer ellenőrzése === PS C:\Users\Administrator> Get-NetFirewallRule -DisplayGroup "Windows Remote Management" Name : WINRM-HTTP-In-TCP DisplayName : Windows Remote Management (HTTP-In) Description : Inbound rule for Windows Remote Management via WS-Management. [TCP 5985] DisplayGroup : Windows Remote Management Group : @FirewallAPI.dll,-30267 Enabled : False Profile : Domain, Private Platform : {} Direction : Inbound Action : Allow EdgeTraversalPolicy : Block LooseSourceMapping : False LocalOnlyMapping : False Owner : PrimaryStatus : OK Status : The rule was parsed successfully from the store. (65536) EnforcementStatus : NotApplicable PolicyStoreSource : PersistentStore PolicyStoreSourceType : Local RemoteDynamicKeywordAddresses : {} Name : WINRM-HTTP-In-TCP-PUBLIC DisplayName : Windows Remote Management (HTTP-In) Description : Inbound rule for Windows Remote Management via WS-Management. [TCP 5985] DisplayGroup : Windows Remote Management Group : @FirewallAPI.dll,-30267 Enabled : False Profile : Public Platform : {} Direction : Inbound Action : Allow EdgeTraversalPolicy : Block LooseSourceMapping : False LocalOnlyMapping : False Owner : PrimaryStatus : OK Status : The rule was parsed successfully from the store. (65536) EnforcementStatus : NotApplicable PolicyStoreSource : PersistentStore PolicyStoreSourceType : Local RemoteDynamicKeywordAddresses : {} === Hozzáférés engedélyezése === PS C:\Users\Administrator> Enable-NetFirewallRule -DisplayGroup "Windows Remote Management" === Tűzfal szabályrendszer ismételt ellenőrzése === PS C:\Users\Administrator> Get-NetFirewallRule -DisplayGroup "Windows Remote Management" Name : WINRM-HTTP-In-TCP DisplayName : Windows Remote Management (HTTP-In) Description : Inbound rule for Windows Remote Management via WS-Management. [TCP 5985] DisplayGroup : Windows Remote Management Group : @FirewallAPI.dll,-30267 Enabled : True Profile : Domain, Private Platform : {} Direction : Inbound Action : Allow EdgeTraversalPolicy : Block LooseSourceMapping : False LocalOnlyMapping : False Owner : PrimaryStatus : OK Status : The rule was parsed successfully from the store. (65536) EnforcementStatus : NotApplicable PolicyStoreSource : PersistentStore PolicyStoreSourceType : Local RemoteDynamicKeywordAddresses : {} Name : WINRM-HTTP-In-TCP-PUBLIC DisplayName : Windows Remote Management (HTTP-In) Description : Inbound rule for Windows Remote Management via WS-Management. [TCP 5985] DisplayGroup : Windows Remote Management Group : @FirewallAPI.dll,-30267 Enabled : True Profile : Public Platform : {} Direction : Inbound Action : Allow EdgeTraversalPolicy : Block LooseSourceMapping : False LocalOnlyMapping : False Owner : PrimaryStatus : OK Status : The rule was parsed successfully from the store. (65536) EnforcementStatus : NotApplicable PolicyStoreSource : PersistentStore PolicyStoreSourceType : Local RemoteDynamicKeywordAddresses : {} ==== Szolgáltatás ellenőrzése (ansible) ==== === Ellenőrző műveletek === [ansible@ansible ~]$ curl -v http://192.168.110.51:5985/wsman * Trying 192.168.110.51:5985... * Connected to 192.168.110.51 (192.168.110.51) port 5985 * using HTTP/1.x > GET /wsman HTTP/1.1 > Host: 192.168.110.51:5985 > User-Agent: curl/8.12.1 > Accept: */* > * Request completely sent off < HTTP/1.1 405 < Allow: POST < Server: Microsoft-HTTPAPI/2.0 < Date: Tue, 26 May 2026 07:27:53 GMT < Connection: close < Content-Length: 0 < * shutting down connection #0 ===== Rendszerinformációk ===== ==== Ansible "tények" lekérdezése ==== Hozzunk létre egyszerű, ansible tényeket lekérdező ansible playbook állományt - hosts: windows gather_facts: true tasks: - debug: var: ansible_facts Futtassuk a playbook-ot [ansible@ansible ~]$ ansible-playbook 01-facts.yaml PLAY [windows] ***************************************************************** TASK [Gathering Facts] ********************************************************* ok: [win2022] TASK [debug] ******************************************************************* ok: [win2022] => { "ansible_facts": { "architecture": "64-bit", "architecture2": "x86_64", "bios_date": "11. 17. 2024", "bios_version": "edk2-20241117-4.el9_7.3", "date_time": { "date": "2026-05-25", "day": "25", "epoch": "1779775803,95348", "epoch_int": 1779775804, "epoch_local": "1779750603,95348", "hour": "23", "iso8601": "2026-05-26T06:10:03Z", "iso8601_basic": "20260525T231003953480", "iso8601_basic_short": "20260525T231003", "iso8601_micro": "2026-05-26T06:10:03.953480Z", "minute": "10", "month": "05", "second": "03", "time": "23:10:03", "tz": "Pacific Standard Time", "tz_offset": "-07:00", "weekday": "Monday", "weekday_number": "1", "weeknumber": "20", "year": "2026" }, "distribution": "Microsoft Windows Server 2022 Standard Evaluation", "distribution_major_version": "10", "distribution_version": "10.0.20348.0", "domain": "", "env": { "ALLUSERSPROFILE": "C:\\ProgramData", "APPDATA": "C:\\Users\\Administrator\\AppData\\Roaming", "COMPUTERNAME": "WIN-T9R338V1CCC", "ComSpec": "C:\\Windows\\system32\\cmd.exe", "CommonProgramFiles": "C:\\Program Files\\Common Files", "CommonProgramFiles(x86)": "C:\\Program Files (x86)\\Common Files", "CommonProgramW6432": "C:\\Program Files\\Common Files", "DriverData": "C:\\Windows\\System32\\Drivers\\DriverData", "HOMEDRIVE": "C:", "HOMEPATH": "\\Users\\Administrator", "LOCALAPPDATA": "C:\\Users\\Administrator\\AppData\\Local", "LOGONSERVER": "\\\\WIN-T9R338V1CCC", "NUMBER_OF_PROCESSORS": "2", "OS": "Windows_NT", "PATHEXT": ".COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC;.CPL", "PROCESSOR_ARCHITECTURE": "AMD64", "PROCESSOR_IDENTIFIER": "AMD64 Family 23 Model 17 Stepping 0, AuthenticAMD", "PROCESSOR_LEVEL": "23", "PROCESSOR_REVISION": "1100", "PROMPT": "$P$G", "PSExecutionPolicyPreference": "Unrestricted", "PSModulePath": "C:\\Users\\Administrator\\Documents\\WindowsPowerShell\\Modules;C:\\Program Files\\WindowsPowerShell\\Modules;C:\\Windows\\system32\\WindowsPowerShell\\v1.0\\Modules", "PUBLIC": "C:\\Users\\Public", "Path": "C:\\Windows\\system32;C:\\Windows;C:\\Windows\\System32\\Wbem;C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\;C:\\Windows\\System32\\OpenSSH\\;C:\\Users\\Administrator\\AppData\\Local\\Microsoft\\WindowsApps", "ProgramData": "C:\\ProgramData", "ProgramFiles": "C:\\Program Files", "ProgramFiles(x86)": "C:\\Program Files (x86)", "ProgramW6432": "C:\\Program Files", "SystemDrive": "C:", "SystemRoot": "C:\\Windows", "TEMP": "C:\\Users\\ADMINI~1\\AppData\\Local\\Temp", "TMP": "C:\\Users\\ADMINI~1\\AppData\\Local\\Temp", "USERDOMAIN": "WIN-T9R338V1CCC", "USERDOMAIN_ROAMINGPROFILE": "WIN-T9R338V1CCC", "USERNAME": "Administrator", "USERPROFILE": "C:\\Users\\Administrator", "windir": "C:\\Windows" }, "fqdn": "WIN-T9R338V1CCC", "gather_subset": [ "all" ], "hostname": "WIN-T9R338V1CCC", "interfaces": [ { "connection_name": "Ethernet Instance 0", "default_gateway": "192.168.110.1", "dns_domain": null, "interface_index": 4, "interface_name": "Intel(R) 82574L Gigabit Network Connection", "ipv4": { "address": "192.168.110.51", "prefix": "24" }, "ipv6": { "address": "fe80::317d:e4ae:1de6:e99c%4", "prefix": "64" }, "macaddress": "52:54:00:8E:F9:1E", "mtu": 1500, "speed": 1000 } ], "ip_addresses": [ "fe80::317d:e4ae:1de6:e99c%4", "192.168.110.51" ], "kernel": "10.0.20348.0", "lastboot": "2026-05-21 00:04:04Z", "machine_id": "S-1-5-21-3572516673-4086879683-2416554126", "memfree_mb": 4399, "memtotal_mb": 8173, "module_setup": true, "netbios_name": "WIN-T9R338V1CCC", "nodename": "WIN-T9R338V1CCC", "os_family": "Windows", "os_install_date": "2026-05-09T02:53:01Z", "os_installation_type": "Server", "os_name": "Microsoft Windows Server 2022 Standard Evaluation", "os_product_type": "server", "owner_contact": "", "owner_name": "Windows User", "pagefilefree_mb": 1061, "pagefiletotal_mb": 1280, "powershell_version": 5, "processor": [ "0", "AuthenticAMD", "AMD Ryzen 3 PRO 2200GE w/ Radeon Vega Graphics ", "1", "AuthenticAMD", "AMD Ryzen 3 PRO 2200GE w/ Radeon Vega Graphics " ], "processor_cores": 2, "processor_count": 1, "processor_threads_per_core": 1, "processor_vcpus": 2, "product_name": "KVM", "product_serial": null, "product_uuid": "5EF55895-6169-4C7E-9E28-23CD198B8D5F", "reboot_pending": true, "swaptotal_mb": 0, "system": "Win32NT", "system_description": "", "system_vendor": "Red Hat", "uptime_seconds": 428761, "user_dir": "C:\\Users\\Administrator", "user_gecos": "", "user_id": "Administrator", "user_sid": "S-1-5-21-3572516673-4086879683-2416554126-500", "virtualization_role": "guest", "virtualization_type": "kvm", "windows_domain": "WORKGROUP", "windows_domain_member": false, "windows_domain_role": "Stand-alone server" } } PLAY RECAP ********************************************************************* win2022 : ok=2 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 ==== Windows rendszerinformációk ==== [ansible@ansible ~]$ cat 02-osinfo.yaml - hosts: windows gather_facts: false tasks: - name: OS info ansible.windows.win_powershell: script: | Get-CimInstance Win32_OperatingSystem | Select-Object Caption, Version, BuildNumber, OSArchitecture | ConvertTo-Json -Depth 3 register: osinfo - debug: msg: "{{ osinfo.output[0] }}" [ansible@ansible ~]$ ansible-playbook 02-osinfo.yaml PLAY [windows] ***************************************************************** TASK [OS info] ***************************************************************** changed: [win2022] TASK [debug] ******************************************************************* ok: [win2022] => { "msg": { "BuildNumber": "20348", "Caption": "Microsoft Windows Server 2022 Standard Evaluation", "OSArchitecture": "64-bit", "Version": "10.0.20348" } } PLAY RECAP ********************************************************************* win2022 : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 ===== Felhasználók kezelése ===== ==== Helyi felhasználó létrehozása ==== - hosts: windows tasks: - name: Create local user ansible.windows.win_user: name: "user1" password: "Linux2026%" state: present password_never_expires: true user_cannot_change_password: true groups: - Users [ansible@ansible ~]$ ansible-playbook 03-create-local-user.yaml PLAY [windows] ***************************************************************** TASK [Gathering Facts] ********************************************************* ok: [win2022] TASK [Create local user] ******************************************************* changed: [win2022] PLAY RECAP ********************************************************************* win2022 : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 ==== Helyi felhasználó módosítása ==== - hosts: windows tasks: - name: Add user1 to local Administrators ansible.windows.win_group_membership: name: Administrators members: - user1 state: present [ansible@ansible ~]$ ansible-playbook 03-modify-local-user.yaml PLAY [windows] ***************************************************************** TASK [Gathering Facts] ********************************************************* ok: [win2022] TASK [Add user1 to local Administrators] *************************************** changed: [win2022] PLAY RECAP ********************************************************************* win2022 : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 ==== Helyi felhasználó törlése ==== - hosts: windows tasks: - name: Delete user profile ansible.windows.win_user_profile: username: user1 state: absent - name: Delete local Windows user ansible.windows.win_user: name: user1 state: absent [ansible@ansible ~]$ ansible-playbook 03-delete-local-user.yaml PLAY [windows] ***************************************************************** TASK [Gathering Facts] ********************************************************* ok: [win2022] TASK [Delete user profile] ***************************************************** ok: [win2022] TASK [Delete local Windows user] *********************************************** changed: [win2022] PLAY RECAP ********************************************************************* win2022 : ok=3 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 Windows oldalon a profil és a felhasználó törlése adminisztrátorként futtatott PS utasítások segítségével elvégezhető: PS C:\Users\Administrator> Get-CimInstance Win32_UserProfile | Where LocalPath -eq "C:\Users\USERNAME" | Remove-CimInstance PS C:\Users\Administrator> Remove-LocalUser USERNAME Ugyanez megoldható szkript segítségével $user = "USERNAME" Get-CimInstance Win32_UserProfile | Where-Object { $_.LocalPath -eq "C:\Users\$USERNAME" } | ForEach-Object { if (-not $_.Loaded) { Remove-CimInstance $_ } } ==== Több felhasználó létrehozása ==== - hosts: windows vars: local_users: - { name: "user2", pass: "Linux2026%" } - { name: "user3", pass: "Linux2026%" } - { name: "user4", pass: "Linux2026%" } tasks: - ansible.windows.win_user: name: "{{ item.name }}" password: "{{ item.pass }}" state: present loop: "{{ local_users }}" [ansible@ansible ~]$ ansible-playbook 03-create-local-users.yaml PLAY [windows] ***************************************************************** TASK [Gathering Facts] ********************************************************* ok: [win2022] TASK [ansible.windows.win_user] ************************************************ changed: [win2022] => (item={'name': 'user2', 'pass': 'Linux2026%'}) changed: [win2022] => (item={'name': 'user3', 'pass': 'Linux2026%'}) changed: [win2022] => (item={'name': 'user4', 'pass': 'Linux2026%'}) PLAY RECAP ********************************************************************* win2022 : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 A felhasználók lekérdezhetők PowerShell segítségével. PS C:\Users\Administrator> Get-LocalUser | Select-Object Name | Select-String 'user' @{Name=user2} @{Name=user3} @{Name=user4} ==== Több felhasználó törlése ==== - hosts: windows vars: local_users: - user2 - user3 - user4 tasks: - name: Delete user profiles first ansible.windows.win_user_profile: username: "{{ item }}" state: absent loop: "{{ local_users }}" - name: Delete local Windows users ansible.windows.win_user: name: "{{ item }}" state: absent loop: "{{ local_users }}" [ansible@ansible ~]$ ansible-playbook 03-delete-local-users.yaml PLAY [windows] ***************************************************************** TASK [Gathering Facts] ********************************************************* ok: [win2022] TASK [Delete user profiles first] ********************************************** ok: [win2022] => (item=user2) ok: [win2022] => (item=user3) ok: [win2022] => (item=user4) TASK [Delete local Windows users] ********************************************** changed: [win2022] => (item=user2) changed: [win2022] => (item=user3) changed: [win2022] => (item=user4) PLAY RECAP ********************************************************************* win2022 : ok=3 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 ===== Active Directory szolgáltatások ===== Ebben a példában az Active Directory szerver ''kutyacica.lan'' tartománya a ''adc.kutyacica.lan'' gépen érhető el. ==== Előkészítő műveletek ==== Ansible gépen telepíteni kell a ''microsoft.ad'' gyűjteményt. [ansible@ansible ~]$ ansible-galaxy collection install microsoft.ad Starting galaxy collection install process Process install dependency map Starting collection install process Downloading https://galaxy.ansible.com/api/v3/plugin/ansible/content/published/collections/artifacts/microsoft-ad-1.11.0.tar.gz to /home/ansible/.ansible/tmp/ansible-local-67186v5wyun37/tmpplulm2oa/microsoft-ad-1.11.0-p_fjaa6z Installing 'microsoft.ad:1.11.0' to '/home/ansible/.ansible/collections/ansible_collections/microsoft/ad' microsoft.ad:1.11.0 was installed successfully [ansible@ansible ~]$ ansible-galaxy collection list # /home/ansible/.ansible/collections/ansible_collections Collection Version ----------------- ------- ansible.windows 3.5.0 community.windows 3.2.0 microsoft.ad 1.11.0 ==== Szervezeti egység létrehozása ==== - name: Create AD organizational units hosts: windows gather_facts: false tasks: - name: Create Users OU microsoft.ad.ou: name: TanfolyamUsers path: DC=kutyacica,DC=lan state: present - name: Create Groups OU microsoft.ad.ou: name: TanfolyamGroups path: DC=kutyacica,DC=lan state: present [ansible@ansible ~]$ ansible-playbook 04-create-ad-ou.yaml PLAY [Create AD organizational units] ****************************************** TASK [Create Users OU] ********************************************************* changed: [adc] TASK [Create Groups OU] ******************************************************** changed: [adc] PLAY RECAP ********************************************************************* adc : ok=2 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 ==== Csoport létrehozása ==== - name: Create AD group hosts: windows gather_facts: false tasks: - name: Create global security group microsoft.ad.group: name: LinuxAdmins path: OU=TanfolyamGroups,DC=kutyacica,DC=lan scope: global category: security description: Linux rendszergazdák state: present [ansible@ansible ~]$ ansible-playbook 04-create-ad-group.yaml PLAY [Create AD group] ********************************************************* TASK [Create global security group] ******************************************** changed: [adc] PLAY RECAP ********************************************************************* adc : ok=1 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 ==== Felhasználó létrehozása ==== - name: Create AD user hosts: windows gather_facts: false tasks: - name: Create user jkovacs microsoft.ad.user: name: jkovacs firstname: János surname: Kovács display_name: "Kovács János" upn: jkovacs@kutyacica.lan sam_account_name: jkovacs path: OU=TanfolyamUsers,DC=kutyacica,DC=lan password: "KezdoJelszo123!" enabled: true state: present [ansible@ansible ~]$ ansible-playbook 04-create-ad-user.yaml PLAY [Create AD user] ********************************************************** TASK [Create user jkovacs] ***************************************************** changed: [adc] PLAY RECAP ********************************************************************* adc : ok=1 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 ==== Felhasználó módosítása ==== - name: Modify AD user attributes hosts: windows gather_facts: false tasks: - name: Modify user attributes microsoft.ad.user: identity: jkovacs firstname: János surname: Kovács display_name: "Kovács János" description: "Linux oktató" company: "Kutyacica Kft." city: "Budapest" state_province: "Budapest" street: "Fő utca 1" postal_code: "1111" country: "HU" email: "jkovacs@kutyacica.lan" attributes: set: department: "IT" title: "Senior Linux Administrator" telephoneNumber: "+3612345678" enabled: true state: present [ansible@ansible ~]$ ansible-playbook 04-modify-ad-user.yaml PLAY [Modify AD user attributes] *********************************************** TASK [Modify user attributes] ************************************************** changed: [adc] PLAY RECAP ********************************************************************* adc : ok=1 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 Megjegyzés: Az attribútumok közül közvetlenül csak az alábbi lista elemei módosíthatók: domain_username, postal_code, delegates, city, update_password, enabled, password, domain_credentials, spn, path, street, password_expired, identity, groups, upn, country, protect_from_deletion, state, state_province, sam_account_name, email, company, attributes, domain_server, surname, description, password_never_expires, account_locked, firstname, display_name, name, user_cannot_change_password, domain_password, principals_allowed_to_delegate, spns, lastname Minden más esetben az attribútum az attributes: set: attributeName: érték módszerrel módosítható. ==== Felhasználó jelszavának cseréje ==== - name: Change AD user password hosts: windows gather_facts: false tasks: - name: Set new password microsoft.ad.user: identity: jkovacs password: "UjJelszo123!" update_password: always state: present [ansible@ansible ~]$ ansible-playbook 04-change-ad-user-password.yaml PLAY [Change AD user password] ************************************************* TASK [Set new password] ******************************************************** changed: [adc] PLAY RECAP ********************************************************************* adc : ok=1 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 ==== Felhasználó tiltása ==== - name: Disable AD user hosts: windows gather_facts: false tasks: - name: Disable user microsoft.ad.user: identity: jkovacs enabled: false state: present [ansible@ansible ~]$ ansible-playbook 04-disable-ad-user.yaml PLAY [Disable AD user] ********************************************************* TASK [Disable user] ************************************************************ changed: [adc] PLAY RECAP ********************************************************************* adc : ok=1 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 ==== Felhasználó engedélyezése ==== - name: Enable AD user hosts: windows gather_facts: false tasks: - name: Enable user microsoft.ad.user: identity: jkovacs enabled: true state: present [ansible@ansible ~]$ ansible-playbook 04-enable-ad-user.yaml PLAY [Enable AD user] ********************************************************** TASK [Enable user] ************************************************************ changed: [adc] PLAY RECAP ********************************************************************* adc : ok=1 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 ==== Felhasználó törlése ==== - name: Delete AD user hosts: windows gather_facts: false tasks: - name: Delete user microsoft.ad.user: identity: jkovacs state: absent [ansible@ansible ~]$ ansible-playbook 04-delete-ad-user.yaml PLAY [Delete AD user] ********************************************************** TASK [Delete user] ************************************************************* changed: [adc] PLAY RECAP ********************************************************************* adc : ok=1 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 ==== Csoport törlése ==== - name: Delete AD group hosts: windows gather_facts: false tasks: - name: Delete global security group microsoft.ad.group: name: LinuxAdmins state: absent [ansible@ansible ~]$ ansible-playbook 04-delete-ad-group.yaml PLAY [Delete AD group] ********************************************************* TASK [Delete global security group] ******************************************** ok: [adc] PLAY RECAP ********************************************************************* adc : ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 ==== Szervezeti egység törlése ==== - name: Delete AD organizational units hosts: windows gather_facts: false tasks: - name: Delete Users OU microsoft.ad.ou: name: TanfolyamUsers path: DC=kutyacica,DC=lan state: absent - name: Delete Groups OU microsoft.ad.ou: name: TanfolyamGroups path: DC=kutyacica,DC=lan state: absent [ansible@ansible ~]$ ansible-playbook 04-delete-ad-ou.yaml PLAY [Delete AD organizational units] ****************************************** TASK [Delete Users OU] ********************************************************* changed: [adc] TASK [Delete Groups OU] ******************************************************** changed: [adc] PLAY RECAP ********************************************************************* adc : ok=2 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 ==== Teljes példa ==== 04-ad.yaml - name: Manage AD objects hosts: windows gather_facts: false vars: ad_state: present domain_dn: "DC=kutyacica,DC=lan" ad_ous: - name: TanfolyamUsers path: "{{ domain_dn }}" - name: TanfolyamGroups path: "{{ domain_dn }}" ad_groups: - name: LinuxAdmins path: "OU=TanfolyamGroups,{{ domain_dn }}" scope: global category: security ad_users: - username: jkovacs firstname: János surname: Kovács - username: nagy.peter firstname: Péter surname: Nagy tasks: - name: Create OUs microsoft.ad.ou: name: "{{ item.name }}" path: "{{ item.path }}" protect_from_deletion: false state: present loop: "{{ ad_ous }}" when: ad_state == "present" - name: Create groups microsoft.ad.group: name: "{{ item.name }}" path: "{{ item.path }}" scope: "{{ item.scope }}" category: "{{ item.category }}" state: present loop: "{{ ad_groups }}" when: ad_state == "present" - name: Create users microsoft.ad.user: name: "{{ item.username }}" firstname: "{{ item.firstname }}" surname: "{{ item.surname }}" display_name: "{{ item.surname }} {{ item.firstname }}" upn: "{{ item.username }}@kutyacica.lan" sam_account_name: "{{ item.username }}" path: "OU=TanfolyamUsers,{{ domain_dn }}" password: "KezdoJelszo123!" enabled: true state: present loop: "{{ ad_users }}" when: ad_state == "present" - name: Add users to group microsoft.ad.group: name: LinuxAdmins path: "OU=TanfolyamGroups,{{ domain_dn }}" members: add: "{{ ad_users | map(attribute='username') | list }}" state: present when: ad_state == "present" - name: Delete users microsoft.ad.user: identity: "{{ item.username }}" state: absent loop: "{{ ad_users }}" when: ad_state == "absent" - name: Delete groups microsoft.ad.group: identity: "{{ item.name }}" state: absent loop: "{{ ad_groups }}" when: ad_state == "absent" - name: Delete OUs microsoft.ad.ou: name: "{{ item.name }}" path: "{{ item.path }}" state: absent loop: "{{ ad_ous | reverse | list }}" when: ad_state == "absent" === Létrehozás === [ansible@ansible ~]$ ansible-playbook 04-ad.yaml -e ad_state=present PLAY [Manage AD objects] ******************************************************* TASK [Create OUs] ************************************************************** changed: [adc] => (item={'name': 'TanfolyamUsers', 'path': 'DC=kutyacica,DC=lan'}) changed: [adc] => (item={'name': 'TanfolyamGroups', 'path': 'DC=kutyacica,DC=lan'}) TASK [Create groups] *********************************************************** changed: [adc] => (item={'name': 'LinuxAdmins', 'path': 'OU=TanfolyamGroups,DC=kutyacica,DC=lan', 'scope': 'global', 'category': 'security'}) TASK [Create users] ************************************************************ changed: [adc] => (item={'username': 'jkovacs', 'firstname': 'János', 'surname': 'Kovács'}) changed: [adc] => (item={'username': 'nagy.peter', 'firstname': 'Péter', 'surname': 'Nagy'}) TASK [Add users to group] ****************************************************** changed: [adc] TASK [Delete users] ************************************************************ skipping: [adc] => (item={'username': 'jkovacs', 'firstname': 'János', 'surname': 'Kovács'}) skipping: [adc] => (item={'username': 'nagy.peter', 'firstname': 'Péter', 'surname': 'Nagy'}) skipping: [adc] TASK [Delete groups] *********************************************************** skipping: [adc] => (item={'name': 'LinuxAdmins', 'path': 'OU=TanfolyamGroups,DC=kutyacica,DC=lan', 'scope': 'global', 'category': 'security'}) skipping: [adc] TASK [Delete OUs] ************************************************************** skipping: [adc] => (item={'name': 'TanfolyamGroups', 'path': 'DC=kutyacica,DC=lan'}) skipping: [adc] => (item={'name': 'TanfolyamUsers', 'path': 'DC=kutyacica,DC=lan'}) skipping: [adc] PLAY RECAP ********************************************************************* adc : ok=4 changed=4 unreachable=0 failed=0 skipped=3 rescued=0 ignored=0 === Törlés === [ansible@ansible ~]$ ansible-playbook 04-ad.yaml -e ad_state=absent PLAY [Manage AD objects] ******************************************************* TASK [Create OUs] ************************************************************** skipping: [adc] => (item={'name': 'TanfolyamUsers', 'path': 'DC=kutyacica,DC=lan'}) skipping: [adc] => (item={'name': 'TanfolyamGroups', 'path': 'DC=kutyacica,DC=lan'}) skipping: [adc] TASK [Create groups] *********************************************************** skipping: [adc] => (item={'name': 'LinuxAdmins', 'path': 'OU=TanfolyamGroups,DC=kutyacica,DC=lan', 'scope': 'global', 'category': 'security'}) skipping: [adc] TASK [Create users] ************************************************************ skipping: [adc] => (item={'username': 'jkovacs', 'firstname': 'János', 'surname': 'Kovács'}) skipping: [adc] => (item={'username': 'nagy.peter', 'firstname': 'Péter', 'surname': 'Nagy'}) skipping: [adc] TASK [Add users to group] ****************************************************** skipping: [adc] TASK [Delete users] ************************************************************ changed: [adc] => (item={'username': 'jkovacs', 'firstname': 'János', 'surname': 'Kovács'}) changed: [adc] => (item={'username': 'nagy.peter', 'firstname': 'Péter', 'surname': 'Nagy'}) TASK [Delete groups] *********************************************************** changed: [adc] => (item={'name': 'LinuxAdmins', 'path': 'OU=TanfolyamGroups,DC=kutyacica,DC=lan', 'scope': 'global', 'category': 'security'}) TASK [Delete OUs] ************************************************************** changed: [adc] => (item={'name': 'TanfolyamGroups', 'path': 'DC=kutyacica,DC=lan'}) changed: [adc] => (item={'name': 'TanfolyamUsers', 'path': 'DC=kutyacica,DC=lan'}) PLAY RECAP ********************************************************************* adc : ok=3 changed=3 unreachable=0 failed=0 skipped=4 rescued=0 ignored=0 ===== Könyvtárak és fájlok ===== ==== Könyvtár létrehozás ==== - name: Directory management demo hosts: windows gather_facts: false tasks: - name: Create application root directory ansible.windows.win_file: path: C:\apps state: directory - name: Create application subdirectories ansible.windows.win_file: path: "C:\\apps\\{{ item }}" state: directory loop: - conf - logs - data - backup - temp [ansible@ansible ~]$ ansible-playbook 05-create-directory.yaml PLAY [Directory management demo] *********************************************** TASK [Create application root directory] *************************************** changed: [adc] TASK [Create application subdirectories] *************************************** changed: [adc] => (item=conf) changed: [adc] => (item=logs) changed: [adc] => (item=data) changed: [adc] => (item=backup) changed: [adc] => (item=temp) PLAY RECAP ********************************************************************* adc : ok=2 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 ==== Könyvtár ellenőrzése ==== - name: Verify directory existence hosts: windows gather_facts: false tasks: - name: Check application directory ansible.windows.win_stat: path: C:\apps register: apps_dir - name: Display directory status ansible.builtin.debug: var: apps_dir.stat.exists [ansible@ansible ~]$ ansible-playbook 05-check-directory.yaml PLAY [Verify directory existence] ********************************************** TASK [Check application directory] ********************************************* ok: [adc] TASK [Display directory status] ************************************************ ok: [adc] => { "apps_dir.stat.exists": true } PLAY RECAP ********************************************************************* adc : ok=2 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 ==== Könyvtár törlés ==== A könyvtár törlése eltávolítja a könyvtár tartalmát (alkönyvtárak, fájlok). - name: Remove temporary directory hosts: windows gather_facts: false tasks: - name: Delete temp directory ansible.windows.win_file: path: C:\apps\temp state: absent [ansible@ansible ~]$ ansible-playbook 05-delete-directory.yaml PLAY [Remove temporary directory] ********************************************** TASK [Delete temp directory] *************************************************** changed: [adc] PLAY RECAP ********************************************************************* adc : ok=1 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 === Több könyvtár törlése === - name: Remove multiple directories hosts: windows gather_facts: false tasks: - name: Delete selected directories ansible.windows.win_file: path: "C:\\apps\\{{ item }}" state: absent loop: - backup - temp [ansible@ansible ~]$ ansible-playbook 05-delete-multiple-directories.yaml PLAY [Remove multiple directories] ********************************************* TASK [Delete selected directories] ********************************************* changed: [adc] => (item=backup) changed: [adc] => (item=temp) PLAY RECAP ********************************************************************* adc : ok=1 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 ==== Könyvtár tartalom megjelenítése ==== - name: List directory contents hosts: windows gather_facts: false tasks: - name: List files and directories ansible.windows.win_shell: | Get-ChildItem C:\apps register: dir_listing - name: Display directory contents ansible.builtin.debug: var: dir_listing.stdout_lines [ansible@ansible ~]$ ansible-playbook 05-list-directory-content-recursive.yaml PLAY [List directory contents] ************************************************* TASK [List files and directories] ********************************************** changed: [adc] TASK [Display directory contents] ********************************************** ok: [adc] => { "dir_listing.stdout_lines": [ "", "", " Directory: C:\\apps", "", "", "Mode LastWriteTime Length Name ", "---- ------------- ------ ---- ", "d----- 2026. 05. 28. 19:19 conf ", "d----- 2026. 05. 28. 19:19 data ", "d----- 2026. 05. 28. 19:19 logs ", "", "" ] } PLAY RECAP ********************************************************************* adc : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 ==== Fájl létrehozás ==== - name: Create empty file hosts: windows gather_facts: false tasks: - name: Create log file ansible.windows.win_file: path: C:\apps\logs\app.log state: touch [ansible@ansible ~]$ ansible-playbook 05-create-empty-file.yaml PLAY [Create empty file] ******************************************************* TASK [Create log file] ********************************************************* changed: [adc] PLAY RECAP ********************************************************************* adc : ok=1 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 - name: Create configuration file hosts: windows gather_facts: false tasks: - name: Create application configuration file ansible.windows.win_copy: dest: C:\apps\conf\app.conf content: | app_name=DemoApp environment=training log_level=info data_dir=C:\apps\data [ansible@ansible ~]$ ansible-playbook 05-create-file-with-content.yaml PLAY [Create configuration file] *********************************************** TASK [Create application configuration file] *********************************** changed: [adc] PLAY RECAP ********************************************************************* adc : ok=1 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 ==== Fájl másolás ==== - name: Copy file to Windows host hosts: windows gather_facts: false tasks: - name: Copy README file ansible.windows.win_copy: src: files/readme.txt dest: C:\apps\readme.txt [ansible@ansible ~]$ mkdir files [ansible@ansible ~]$ echo "Fájl tartalom" > files/readme.txt [ansible@ansible ~]$ ansible-playbook 05-file-copy.yaml PLAY [Copy file to Windows host] *********************************************** TASK [Copy README file] ******************************************************** changed: [adc] PLAY RECAP ********************************************************************* adc : ok=1 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 ==== Fájl ellenőrzés ==== - name: Verify file existence hosts: windows gather_facts: false tasks: - name: Check configuration file ansible.windows.win_stat: path: C:\apps\conf\app.conf register: conf_file - name: Display file status ansible.builtin.debug: var: conf_file.stat.exists [ansible@ansible ~]$ ansible-playbook 05-check-file-existence.yaml PLAY [Verify file existence] *************************************************** TASK [Check configuration file] ************************************************ ok: [adc] TASK [Display file status] ***************************************************** ok: [adc] => { "conf_file.stat.exists": true } PLAY RECAP ********************************************************************* adc : ok=2 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 ==== Fájl tartalom módosítás ==== === Sor csere === - name: Update configuration setting hosts: windows gather_facts: false tasks: - name: Set log level to debug community.windows.win_lineinfile: path: C:\apps\conf\app.conf regexp: '^log_level=' line: 'log_level=debug' [ansible@ansible ~]$ ansible-playbook 05-modify-file.yaml PLAY [Update configuration setting] ******************************************** TASK [Set log level to debug] ************************************************** changed: [adc] PLAY RECAP ********************************************************************* adc : ok=1 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 === Új sor === - name: Add configuration entry hosts: windows gather_facts: false tasks: - name: Add max_clients setting community.windows.win_lineinfile: path: C:\apps\conf\app.conf line: 'max_clients=100' create: true [ansible@ansible ~]$ ansible-playbook 05-add-line-to-file.yaml PLAY [Add configuration entry] ************************************************* TASK [Add max_clients setting] ************************************************* changed: [adc] PLAY RECAP ********************************************************************* adc : ok=1 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 === Sor törlés === - name: Remove configuration entry hosts: windows gather_facts: false tasks: - name: Remove environment setting community.windows.win_lineinfile: path: C:\apps\conf\app.conf regexp: '^environment=' state: absent [ansible@ansible ~]$ ansible-playbook 05-delete-line-from-file.yaml PLAY [Remove configuration entry] ********************************************** TASK [Remove environment setting] ********************************************** changed: [adc] PLAY RECAP ********************************************************************* adc : ok=1 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 === Több sor módosítása === - name: Configure multiple settings hosts: windows gather_facts: false tasks: - name: Configure application settings community.windows.win_lineinfile: path: C:\apps\conf\app.conf regexp: "^{{ item.key }}=" line: "{{ item.key }}={{ item.value }}" create: true loop: - { key: "app_name", value: "DemoApp" } - { key: "log_level", value: "warning" } - { key: "max_clients", value: "200" } [ansible@ansible ~]$ ansible-playbook 05-modify-multiple-lines-in-file.yaml PLAY [Configure multiple settings] ********************************************* TASK [Configure application settings] ****************************************** ok: [adc] => (item={'key': 'app_name', 'value': 'DemoApp'}) changed: [adc] => (item={'key': 'log_level', 'value': 'warning'}) changed: [adc] => (item={'key': 'max_clients', 'value': '200'}) PLAY RECAP ********************************************************************* adc : ok=1 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 ==== Fájl tartalom megjelenítése ==== - name: Read configuration file hosts: windows gather_facts: false tasks: - name: Read configuration file content ansible.windows.win_shell: Get-Content C:\apps\conf\app.conf register: conf_content - name: Display configuration content ansible.builtin.debug: var: conf_content.stdout_lines [ansible@ansible ~]$ ansible-playbook 05-read-file-content.yaml PLAY [Read configuration file] ************************************************* TASK [Read configuration file content] ***************************************** changed: [adc] TASK [Display configuration content] ******************************************* ok: [adc] => { "conf_content.stdout_lines": [ "app_name=DemoApp", "log_level=warning", "data_dir=C:\\apps\\data", "max_clients=200" ] } PLAY RECAP ********************************************************************* adc : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 ===== Ansible vault ===== ==== Fájl műveletek ==== === Létrehozás === [ansible@ansible ~]$ cat > secret.yaml <<'EOF' db_user: appuser db_password: SuperSecret123! EOF === Titkosítás === [ansible@ansible ~]$ ansible-vault encrypt secret.yaml New Vault password: Confirm New Vault password: Encryption successful [ansible@ansible ~]$ cat secret.yaml $ANSIBLE_VAULT;1.1;AES256 66306635613562363439353734343137346161353763636162383363616234303962616363336366 6633396663663462353864393231313461353532373531340a306333616563306133343332373335 61356334383632656432333538366262636261646233363661386638366533616537373034356263 3961353663633331320a383261663839376463396534313237323266306564623637613637373462 39646263383532356362353833393635613732653334646134613262313439313739353331333831 6332343031333734373935336338333638656661386636613730 === Szerkesztés === [ansible@ansible ~]$ ansible-vault edit secret.yaml Vault password: ... === Visszafejtés === [ansible@ansible ~]$ ansible-vault decrypt secret.yaml Vault password: Decryption successful [ansible@ansible ~]$ cat secret.yaml db_user: appuser db_password: SuperSecret123! === Jelszó csere === [ansible@ansible ~]$ ansible-vault rekey secret.yaml Vault password: New Vault password: Confirm New Vault password: Rekey successful ==== Interaktív használat ==== - hosts: localhost vars_files: - secret.yaml tasks: - debug: msg: "DB password: {{ db_password }}" [ansible@ansible ~]$ ansible-playbook 06-vault-test.yaml ERROR! Attempting to decrypt but no vault secrets found [ansible@ansible ~]$ ansible-playbook 06-vault-test.yaml --ask-vault-pass Vault password: PLAY [localhost] *************************************************************** TASK [Gathering Facts] ********************************************************* ok: [localhost] TASK [debug] ******************************************************************* ok: [localhost] => { "msg": "DB password: SuperSecret123!" } PLAY RECAP ********************************************************************* localhost : ok=2 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 ==== Jelszófájl használat ==== [ansible@ansible ~]$ cat > vault.pass <<'EOF' 12345 EOF [ansible@ansible ~]$ chmod 0600 vault.pass [ansible@ansible ~]$ ansible-playbook 06-vault-test.yaml --vault-password-file vault.pass PLAY [localhost] *************************************************************** TASK [Gathering Facts] ********************************************************* ok: [localhost] TASK [debug] ******************************************************************* ok: [localhost] => { "msg": "DB password: SuperSecret123!" } PLAY RECAP ********************************************************************* localhost : ok=2 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 ==== Változó titkosítása ==== [ansible@ansible ~]$ ansible-vault encrypt_string 'SuperSecret123!' --name 'db_password' New Vault password: Confirm New Vault password: Encryption successful db_password: !vault | $ANSIBLE_VAULT;1.1;AES256 64663064386637346261633135653162356330353564373332613430336266313930323061646465 6263373239316131626264623966343962303964343131360a623838393637643131623965663765 39346333613866376437633137643838306330353632616366353966353062326366383232633264 3933303831666237340a383038636464313235353166313661363139316161636464323539653138 3530 - hosts: localhost vars: db_user: appuser db_password: !vault | $ANSIBLE_VAULT;1.1;AES256 64663064386637346261633135653162356330353564373332613430336266313930323061646465 6263373239316131626264623966343962303964343131360a623838393637643131623965663765 39346333613866376437633137643838306330353632616366353966353062326366383232633264 3933303831666237340a383038636464313235353166313661363139316161636464323539653138 3530 tasks: - debug: msg: "DB password: {{ db_password }}" [ansible@ansible ~]$ ansible-playbook 06-internal-vault-test.yaml PLAY [localhost] ***************************************************************************************************************************************************************************** TASK [Gathering Facts] *********************************************************************************************************************************************************************** ok: [localhost] TASK [debug] ********************************************************************************************************************************************************************************* fatal: [localhost]: FAILED! => {"msg": "Attempting to decrypt but no vault secrets found"} PLAY RECAP *********************************************************************************************************************************************************************************** localhost : ok=1 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0 [ansible@ansible ~]$ ansible-playbook 06-internal-vault-test.yaml --vault-password-file vault.pass PLAY [localhost] ***************************************************************************************************************************************************************************** TASK [Gathering Facts] *********************************************************************************************************************************************************************** ok: [localhost] TASK [debug] ********************************************************************************************************************************************************************************* ok: [localhost] => { "msg": "DB password: SuperSecret123!" } PLAY RECAP *********************************************************************************************************************************************************************************** localhost : ok=2 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 ==== Több vault használata ==== [ansible@ansible ~]$ ansible-vault encrypt_string --vault-id dev@prompt 'dev123' --name dev_db_password >> vaults.yaml New vault password (dev): Confirm new vault password (dev): [ansible@ansible ~]$ ansible-vault encrypt_string --vault-id prod@prompt 'prod123' --name prod_db_password >> vaults.yaml New vault password (prod): Confirm new vault password (prod): [ansible@ansible ~]$ cat vaults.yaml dev_db_password: !vault | $ANSIBLE_VAULT;1.2;AES256;dev 34653336386234303265623664386237393761626465626230373133643762613266636434613965 3439333961393832346231353037663662336565306430310a613264636639643865376561316139 65663862386134396237383936356630666664346530376235333834633033643135396236613262 3566653338383735640a323937623663303539346463346338366266353866366234336631613538 6565 prod_db_password: !vault | $ANSIBLE_VAULT;1.2;AES256;prod 63623637666532326637316432396432393431333664323262363937386238303134303264353436 3866336533396262626438616630373863366261366533350a663765316337343863356665363763 36663835643730303734643032643466323732386561633162323332373861656235346462643130 6465303633356331370a363564653465653666656366353166663039333430656163373939326538 6531 - hosts: localhost vars: db_user: appuser vars_files: - vaults.yaml tasks: - debug: msg: "DEV DB password: {{ dev_db_password }}" - debug: msg: "PROD DB password: {{ prod_db_password }}" [ansible@ansible ~]$ ansible-playbook 06-vault-id.yaml --vault-id dev@prompt --vault-id prod@prompt Vault password (dev): Vault password (prod): PLAY [localhost] ***************************************************************************************************************************************************************************** TASK [Gathering Facts] *********************************************************************************************************************************************************************** ok: [localhost] TASK [debug] ********************************************************************************************************************************************************************************* ok: [localhost] => { "msg": "DEV DB password: dev123" } TASK [debug] ********************************************************************************************************************************************************************************* ok: [localhost] => { "msg": "PROD DB password: prod123" } PLAY RECAP *********************************************************************************************************************************************************************************** localhost : ok=3 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 ===== Windows frissítés, ütemezett feladatok ===== ==== Windows frissítés (kritikus és biztonsági javítások) ==== - hosts: windows tasks: - name: Install critical/security updates ansible.windows.win_updates: category_names: - CriticalUpdates - SecurityUpdates reboot: true register: upd - debug: var: upd A frissítés hosszú ideig is eltarthat valamint a gép újraindulhat! [ansible@ansible ~]$ ansible-playbook 99-windows-update.yaml PLAY [windows] ***************************************************************** TASK [Gathering Facts] ********************************************************* ok: [win2022] TASK [Install critical/security updates] *************************************** An exception occurred during task execution. To see the full traceback, use -vvv. The error was: Exception: Timed out waiting for last boot time check (timeout=1200) fatal: [win2022]: FAILED! => {"changed": true, "elapsed": 1208, "failed_update_count": 0, "filtered_updates": {"af2d807f-c5a6-435b-bbba-36023ea98955": {"categories": ["Definition Updates", "Microsoft Defender Antivirus"], "downloaded": false, "filtered_reasons": ["category_names"], "id": "af2d807f-c5a6-435b-bbba-36023ea98955", "installed": false, "kb": ["2267602"], "title": "Security Intelligence Update for Microsoft Defender Antivirus - KB2267602 (Version 1.451.111.0) - Current Channel (Broad)"}, "db5bac0b-a277-4d18-9bfd-6c9b08e3251c": {"categories": ["EU Browser Choice Update-For Europe Only", "Update Rollups", "Windows Server 2016", "Windows Server 2019", "Windows Server, version 1903 and later"], "downloaded": false, "filtered_reasons": ["category_names"], "id": "db5bac0b-a277-4d18-9bfd-6c9b08e3251c", "installed": false, "kb": ["890830"], "title": "Windows Malicious Software Removal Tool x64 - v5.141 (KB890830)"}, "f79e3de9-b030-4984-a5ac-fcaa5dab7e8d": {"categories": ["Microsoft Server operating system-21H2", "Updates"], "downloaded": false, "filtered_reasons": ["category_names"], "id": "f79e3de9-b030-4984-a5ac-fcaa5dab7e8d", "installed": false, "kb": ["5010475"], "title": "2022-02 Cumulative Update Preview for .NET Framework 3.5 and 4.8 for Microsoft server operating system version 21H2 for x64 (KB5010475)"}}, "found_update_count": 2, "installed_update_count": 2, "msg": "Failed to reboot host: Timed out waiting for last boot time check (timeout=1200)", "reboot_required": true, "rebooted": true, "unreachable": false, "updates": {"0ae6f8d8-5a5a-4551-a0cc-ca97524fc415": {"categories": ["Microsoft Server operating system-21H2", "Security Updates"], "downloaded": false, "id": "0ae6f8d8-5a5a-4551-a0cc-ca97524fc415", "installed": true, "kb": ["5088862"], "title": "2026-05 Cumulative Update for .NET Framework 3.5, 4.8 and 4.8.1 for Microsoft server operating system version 21H2 for x64 (KB5088862)"}, "d684f5a6-3ade-4716-9aa1-787d79a36afe": {"categories": ["Security Updates"], "downloaded": false, "id": "d684f5a6-3ade-4716-9aa1-787d79a36afe", "installed": true, "kb": ["5087545"], "title": "2026-05 Cumulative Update for Microsoft server operating system version 21H2 for x64-based Systems (KB5087545)"}}} PLAY RECAP ********************************************************************* win2022 : ok=1 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0 A frissítés nyomon követhető PowerShell segítségével. PS C:\Windows\system32> Get-Service wuauserv,BITS,CryptSvc,TrustedInstaller Status Name DisplayName ------ ---- ----------- Stopped BITS Background Intelligent Transfer Ser... Running CryptSvc Cryptographic Services Running TrustedInstaller Windows Modules Installer Running wuauserv Windows Update PS C:\Windows\system32> Get-Service UsoSvc Status Name DisplayName ------ ---- ----------- Running UsoSvc Update Orchestrator Service PS C:\Windows\system32> Get-Content C:\Windows\Logs\CBS\CBS.log -Tail 20 -wait 2026-05-26 01:55:11, Info DPX hr: 0x8000000a at onecore\base\compress\dpx\src\dpxjob.cpp(2433) 2026-05-26 01:55:11, Info DPX Started DPX phase: Apply Deltas Provided In File 2026-05-26 01:55:13, Info DPX hr: 0x80070012 at onecore\base\compress\dpx\src\ipdcab.cpp(1338) 2026-05-26 01:55:13, Info DPX hr: 0x80070012 at onecore\base\compress\dpx\src\bufcab.cpp(330) 2026-05-26 01:55:13, Info DPX CCabStorage::GetErrorCode(): m_hrFirstError = 0x80070012 2026-05-26 01:55:13, Info DPX hr: 0x80070012 at onecore\base\compress\dpx\src\storage.cpp(466) 2026-05-26 01:55:13, Info DPX hr: 0x80070012 at onecore\base\compress\dpx\src\storage.cpp(58) 2026-05-26 01:55:13, Info DPX hr: 0x80070012 at onecore\base\compress\dpx\src\storage.cpp(565) 2026-05-26 01:55:13, Info DPX hr: 0x80070012 at onecore\base\compress\dpx\src\bufcab.cpp(21) 2026-05-26 01:55:13, Info DPX hr: 0x80070012 at onecore\base\compress\dpx\src\bufcab.cpp(108) 2026-05-26 01:55:13, Info DPX Ended DPX phase: Apply Deltas Provided In File 2026-05-26 01:55:13, Info DPX CJob::Resume completed with status: 0x0 2026-05-26 01:55:13, Info DPX Ended DPX phase: Resume and Download Job 2026-05-26 01:55:13, Info CBS Extracting all files from cabinet \\?\C:\Windows\CbsTemp\31255788_4177394721\Windows10.0-KB5087545-x64.cab\Cab_1_for_KB5087545.cab 2026-05-26 01:55:13, Info DPX Started DPX phase: Resume and Download Job 2026-05-26 01:55:13, Info DPX hr: 0x8000000a at onecore\base\compress\dpx\src\dpxjob.cpp(2433) 2026-05-26 01:55:13, Info DPX Started DPX phase: Apply Deltas Provided In File 2026-05-26 01:55:13, Info DPX Ended DPX phase: Apply Deltas Provided In File 2026-05-26 01:55:13, Info DPX hr: 0x8000000a at onecore\base\compress\dpx\src\dpxjob.cpp(2433) 2026-05-26 01:55:13, Info DPX Started DPX phase: Apply Deltas Provided In File 2026-05-26 02:06:38, Info DPX Ended DPX phase: Apply Deltas Provided In File 2026-05-26 02:06:38, Info DPX CJob::Resume completed with status: 0x0 2026-05-26 02:06:38, Info DPX Ended DPX phase: Resume and Download Job 2026-05-26 02:06:38, Info CBS Extracting all files from cabinet \\?\C:\Windows\CbsTemp\31255788_4177394721\Windows10.0-KB5087545-x64.cab\Cab_2_for_KB5087545.cab 2026-05-26 02:06:38, Info DPX Started DPX phase: Resume and Download Job 2026-05-26 02:06:38, Info DPX hr: 0x8000000a at onecore\base\compress\dpx\src\dpxjob.cpp(2433) 2026-05-26 02:06:38, Info DPX Started DPX phase: Apply Deltas Provided In File 2026-05-26 02:06:38, Info DPX Ended DPX phase: Apply Deltas Provided In File 2026-05-26 02:06:38, Info DPX hr: 0x8000000a at onecore\base\compress\dpx\src\dpxjob.cpp(2433) 2026-05-26 02:06:38, Info DPX Started DPX phase: Apply Deltas Provided In File