03 - Files and Directories¶
Learn how to create and manage files and directories with Mooncake.
What You'll Learn¶
- Creating directories with
state: directory - Creating files with
state: file - Setting file permissions with
mode - Adding content to files
Quick Start¶
What It Does¶
- Creates application directory structure
- Creates files with specific content
- Sets appropriate permissions (755 for directories, 644 for files)
- Creates executable scripts
Key Concepts¶
Creating Directories¶
Creating Empty Files¶
Creating Files with Content¶
- name: Create config file
file:
path: /tmp/config.txt
state: file
content: |
Line 1
Line 2
mode: "0644"
File Permissions¶
Use octal notation in quotes:
- "0644" - rw-r--r-- (readable by all, writable by owner)
- "0755" - rwxr-xr-x (executable by all, writable by owner)
- "0600" - rw------- (only owner can read/write)
Using Variables¶
Permission Examples¶
| Mode | Meaning | Use Case |
|---|---|---|
| 0755 | rwxr-xr-x | Directories, executable scripts |
| 0644 | rw-r--r-- | Regular files, configs |
| 0600 | rw------- | Private files, secrets |
| 0700 | rwx------ | Private directories |
Next Steps¶
Continue to 04-conditionals to learn about conditional execution.