Felhasználói eszközök

Eszközök a webhelyen


ansible:windows

Összehasonlítás

A kiválasztott és az jelenlegi változat között az alábbi különbségek fordulnak elő:

Összehasonlító nézet hivatkozása

Előző változat mindkét oldalonElőző változat
Következő változat
Előző változat
ansible:windows [2026/05/26 12:47] – riba.zoltanansible:windows [2026/05/29 10:00] (aktuális) – [Fájl műveletek] riba.zoltan
Sor 679: Sor 679:
 </code> </code>
  
 +===== 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.
 +
 +<code>
 +[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 
 +</code>
 +
 +==== Szervezeti egység létrehozása ====
 +
 +<file yaml 04-create-ad-ou.yaml>
 +- 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
 +</file>
 +
 +<code>
 +[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   
 +</code>
 +
 +==== Csoport létrehozása ====
 +
 +<file yaml 04-create-ad-group.yaml>
 +- 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
 +</file>
 +
 +<code>
 +[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   
 +</code>
 +
 +==== Felhasználó létrehozása ====
 +
 +<file yaml 04-create-ad-user.yaml>
 +- 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
 +</file>
 +
 +<code>
 +[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   
 +</code>
 +
 +==== Felhasználó módosítása ====
 +
 +<file yaml 04-modify-ad-user.yaml>
 +- 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
 +</file>
 +
 +<code>
 +[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   
 +</code>
 +
 +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
 +
 +<code>
 +        attributes:
 +          set:
 +            attributeName: érték
 +</code>
 +
 +módszerrel módosítható.
 +
 +==== Felhasználó jelszavának cseréje ====
 +
 +<file yaml 04-change-ad-user-password.yaml> 
 +- 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
 +</file>
 +
 +<code>
 +[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   
 +</code>
 +
 +==== Felhasználó tiltása ====
 +
 +<file yaml 04-disable-ad-user.yaml>
 +- name: Disable AD user
 +  hosts: windows
 +  gather_facts: false
 +  tasks:
 +    - name: Disable user
 +      microsoft.ad.user:
 +        identity: jkovacs
 +        enabled: false
 +        state: present
 +</file>
 +
 +<code>
 +[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   
 +</code>
 +
 +==== Felhasználó engedélyezése ====
 +
 +<file yaml 04-enable-ad-user.yaml>
 +- name: Enable AD user
 +  hosts: windows
 +  gather_facts: false
 +  tasks:
 +    - name: Enable user
 +      microsoft.ad.user:
 +        identity: jkovacs
 +        enabled: true
 +        state: present
 +</file>
 +
 +<code>
 +[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   
 +</code>
 +
 +==== Felhasználó törlése ====
 +
 +<file yaml 04-delete-ad-user.yaml>
 +- name: Delete AD user
 +  hosts: windows
 +  gather_facts: false
 +  tasks:
 +    - name: Delete user
 +      microsoft.ad.user:
 +        identity: jkovacs
 +        state: absent
 +</file>
 +
 +<code>
 +[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   
 +</code>
 +
 +==== Csoport törlése ====
 +
 +<file yaml 04-delete-ad-group.yaml>
 +- name: Delete AD group
 +  hosts: windows
 +  gather_facts: false
 +  tasks:
 +    - name: Delete global security group
 +      microsoft.ad.group:
 +        name: LinuxAdmins
 +        state: absent
 +</file>
 +
 +<code>
 +[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   
 +</code>
 +
 +==== Szervezeti egység törlése ====
 +
 +<file yaml 04-delete-ad-ou.yaml>
 +- 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
 +</file>
 +
 +<code>
 +[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   
 +</code>
 +
 +==== Teljes példa ====
 +
 +<file yaml 04-ad.yaml>
 +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"
 +</file>
 +
 +=== Létrehozás ===
 +
 +<code>
 +[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   
 +</code>
 +
 +=== Törlés ===
 +
 +<code>
 +[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   
 +</code>
 +
 +===== Könyvtárak és fájlok =====
 +
 +==== Könyvtár létrehozás ====
 +
 +<file yaml 05-create-directory.yaml>
 +- 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
 +</file>
 +
 +<code>
 +[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   
 +</code>
 +
 +==== Könyvtár ellenőrzése ====
 +
 +<file yaml 05-check-directory.yaml>
 +- 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
 +</file>
 +
 +<code>
 +[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   
 +</code>
 +
 +==== 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).
 +
 +<file yaml 05-delete-directory.yaml>
 +- name: Remove temporary directory
 +  hosts: windows
 +  gather_facts: false
 +
 +  tasks:
 +    - name: Delete temp directory
 +      ansible.windows.win_file:
 +        path: C:\apps\temp
 +        state: absent
 +</file>
 +
 +<code>
 +[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   
 +</code>
 +
 +=== Több könyvtár törlése ===
 +
 +<file yaml 05-delete-multiple-directories.yaml>
 +- 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
 +</file>
 +
 +<code>
 +[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   
 +</code>
 +
 +==== Könyvtár tartalom megjelenítése ====
 +
 +<file yaml 05-list-directory-content-recursive.yaml>
 +- 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
 +
 +</file>
 +
 +<code>
 +[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   
 +</code>
 +
 +==== Fájl létrehozás ====
 +
 +<file yaml 05-create-empty-file.yaml>
 +- 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
 +</file>
 +
 +<code>
 +[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   
 +</code>
 +
 +<file yaml 05-create-file-with-content.yaml>
 +- 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
 +</file>
 +
 +<code>
 +[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   
 +</code>
 +
 +==== Fájl másolás ====
 +
 +<file yaml 05-file-copy.yaml>
 +- 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
 +</file>
 +
 +<code>
 +[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   
 +</code>
 +
 +==== Fájl ellenőrzés ====
 +
 +<file yaml 05-check-file-existence.yaml>
 +- 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
 +</file>
 +
 +<code>
 +[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   
 +</code>
 +
 +==== Fájl tartalom módosítás ====
 +
 +=== Sor csere ===
 +
 +<file yaml 05-modify-file.yaml>
 +- 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'
 +</file>
 +
 +<code>
 +[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   
 +</code>
 +
 +=== Új sor ===
 +
 +<file yaml 05-add-line-to-file.yaml>
 +- 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
 +</file>
 +
 +<code>
 +[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   
 +</code>
 +
 +=== Sor törlés ===
 +
 +<file yaml 05-delete-line-from-file.yaml>
 +- 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
 +</file>
 +
 +<code>
 +[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   
 +</code>
 +
 +=== Több sor módosítása ===
 +
 +<file yaml 05-modify-multiple-lines-in-file.yaml>
 +- 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" }
 +</file>
 +
 +<code>
 +[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   
 +</code>
 +
 +==== Fájl tartalom megjelenítése ====
 +
 +<file yaml 05-read-file-content.yaml>
 +- 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
 +</file>
 +
 +<code>
 +[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   
 +</code>
 +
 +===== Ansible vault =====
 +
 +==== Fájl műveletek ====
 +
 +=== Létrehozás ===
 +
 +<code>
 +[ansible@ansible ~]$ cat > secret.yaml <<'EOF'
 +db_user: appuser
 +db_password: SuperSecret123!
 +EOF
 +</code>
 +
 +=== Titkosítás ===
 +
 +<code>
 +[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
 +</code>
 +
 +=== Szerkesztés ===
 +
 +<code>
 +[ansible@ansible ~]$ ansible-vault edit secret.yaml 
 +Vault password: 
 +...
 +</code>
 +
 +=== Visszafejtés ===
 +
 +<code>
 +[ansible@ansible ~]$ ansible-vault decrypt secret.yaml 
 +Vault password: 
 +Decryption successful
 +
 +[ansible@ansible ~]$ cat secret.yaml 
 +db_user: appuser
 +db_password: SuperSecret123!
 +</code>
 +
 +=== Jelszó csere ===
 +
 +<code>
 +[ansible@ansible ~]$ ansible-vault rekey secret.yaml 
 +Vault password: 
 +New Vault password: 
 +Confirm New Vault password: 
 +Rekey successful
 +</code>
 +
 +==== Interaktív használat ====
 +
 +<file yaml 06-vault-test.yaml>
 +- hosts: localhost
 +  vars_files:
 +    - secret.yaml
 +
 +  tasks:
 +    - debug:
 +        msg: "DB password: {{ db_password }}"
 +</file>
 +
 +<code>
 +[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   
 +</code>
 +
 +==== Jelszófájl használat ====
 +
 +<code>
 +[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   
 +</code>
 +
 +==== Változó titkosítása ====
 +
 +<code>
 +[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
 +</code>
 +
 +<file yaml 06-internal-vault-test.yaml>
 +- 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 }}"
 +</file>
 +
 +<code>
 +[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   
 +</code>
 +
 +==== Több vault használata ====
 +
 +<code>
 +[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
 +</code>
 +
 +<file yaml 06-vault-id.yaml>
 +- 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 }}"
 +</file>
 +
 +<code>
 +[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   
 +</code>
  
 ===== Windows frissítés, ütemezett feladatok ===== ===== Windows frissítés, ütemezett feladatok =====
ansible/windows.1779799668.txt.gz · legutóbbi módosítás: – Szerkesztő: riba.zoltan