This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| - name: Get file list and sizes | |
| hosts: your_host | |
| vars: | |
| directory_path: /path/to/your/directory # Update the directory path | |
| tasks: | |
| - name: Find files | |
| find: | |
| paths: "{{ directory_path }}" | |
| file_type: file | |
| recurse: yes |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| - name: Get total file size | |
| hosts: your_host | |
| vars: | |
| directory_path: /path/to/your/directory # Update the directory path | |
| tasks: | |
| - name: Find files | |
| find: | |
| paths: "{{ directory_path }}" | |
| file_type: file | |
| recurse: yes |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| - name: Get file size with variable | |
| hosts: your_host | |
| vars: | |
| file_path: /path/to/your/file | |
| tasks: | |
| - name: Check file size | |
| stat: | |
| path: "{{ file_path }}" | |
| register: file_info | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| --- | |
| - name: Dictionary playbook example | |
| hosts: localhost | |
| tasks: | |
| - name: Create and Add items to dictionary | |
| set_fact: | |
| userdata: "{{ userdata | default({}) | combine({ item.key: item.value }) }}" | |
| loop: | |
| - key: 'Name' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| - name: Merge dictionaries | |
| hosts: localhost | |
| tasks: | |
| - name: Create dict1 | |
| set_fact: | |
| dict1: | |
| key1: value1 | |
| key2: value2 | |
| - name: Create dict2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| - hosts: localhost | |
| tasks: | |
| - name: Create dictionary | |
| set_fact: | |
| my_dict: "{{ my_dict | default({}) | combine({'key1': 'value1', 'key2': 'value2', 'key3': 'value3'}) }}" | |
| - debug: | |
| var: my_dict | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| - hosts: localhost | |
| tasks: | |
| - name: Create dictionary | |
| set_fact: | |
| my_dict: | |
| name: David | |
| website: howtouselinux.com | |
| - name: Display dictionary values | |
| debug: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| - hosts: localhost | |
| tasks: | |
| - name: Create dictionary | |
| set_fact: | |
| my_dict: "{{ {'key1': 'value1', 'key2': 'value2', 'key3': 'value3'} }}" | |
| - debug: | |
| var: my_dict | |
| PLAY [localhost] ******************************************************************************************************************************************************************************************************* |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| - hosts: localhost | |
| tasks: | |
| - name: Create dictionary | |
| set_fact: | |
| my_dict: | |
| key1: value1 | |
| key2: value2 | |
| key3: value3 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| --- | |
| - name: Define and Use a Dictionary | |
| hosts: localhost | |
| gather_facts: no | |
| vars: | |
| server_config: | |
| server1: | |
| ip: 192.168.1.101 | |
| port: 8080 | |
| user: admin |
NewerOlder