Skip to content

Instantly share code, notes, and snippets.

View howtouselinux's full-sized avatar

howtouselinux howtouselinux

View GitHub Profile
- 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
- 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
- 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
---
- 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'
- name: Merge dictionaries
hosts: localhost
tasks:
- name: Create dict1
set_fact:
dict1:
key1: value1
key2: value2
- name: Create dict2
- hosts: localhost
tasks:
- name: Create dictionary
set_fact:
my_dict: "{{ my_dict | default({}) | combine({'key1': 'value1', 'key2': 'value2', 'key3': 'value3'}) }}"
- debug:
var: my_dict
- hosts: localhost
tasks:
- name: Create dictionary
set_fact:
my_dict:
name: David
website: howtouselinux.com
- name: Display dictionary values
debug:
- hosts: localhost
tasks:
- name: Create dictionary
set_fact:
my_dict: "{{ {'key1': 'value1', 'key2': 'value2', 'key3': 'value3'} }}"
- debug:
var: my_dict
PLAY [localhost] *******************************************************************************************************************************************************************************************************
- hosts: localhost
tasks:
- name: Create dictionary
set_fact:
my_dict:
key1: value1
key2: value2
key3: value3
---
- name: Define and Use a Dictionary
hosts: localhost
gather_facts: no
vars:
server_config:
server1:
ip: 192.168.1.101
port: 8080
user: admin