Skip to content

Commit

Permalink
Adding some more tutorial docs, fixing some docs
Browse files Browse the repository at this point in the history
  • Loading branch information
linsomniac committed Dec 13, 2023
1 parent fff6dbf commit 9b6c2fd
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 21 deletions.
45 changes: 26 additions & 19 deletions docs/templating.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,28 +25,35 @@ The following information is available in the `platform` namespace on the follow
platforms:

- Linux:
- arch: 'x86_64',
- release_codename: 'jammy',
- release_id: 'ubuntu',
- os_family: 'debian',
- release_name: 'Ubuntu',
- release_version: '22.04',
- system: 'Linux'

- arch: 'x86_64',
- release_codename: 'jammy',
- release_id: 'ubuntu',
- os_family: 'debian',
- release_name: 'Ubuntu',
- release_version: '22.04',
- system: 'Linux'

- MacOS:
- arch: 'arm64',
- release_version: '13.0.1',
- system: 'Darwin'

- arch: 'arm64',
- release_version: '13.0.1',
- system: 'Darwin'

- Windows:
- arch: 'AMD64',
- release_edition: 'ServerStandard',
- release_name: '10',
- release_version: '10.0.17763',
- system: 'Windows'

- arch: 'AMD64',
- release_edition: 'ServerStandard',
- release_name: '10',
- release_version: '10.0.17763',
- system: 'Windows'

- Platforms with "psutil" module available:
- memory_total = Total memory
- memory_available = Available memory
- memory_used = Used memory
- memory_percent_used = Percent used

- memory_total = Total memory
- memory_available = Available memory
- memory_used = Used memory
- memory_percent_used = Percent used

## Additional Filters

Expand Down
32 changes: 31 additions & 1 deletion docs/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ template_filenames=True, recursive=True) (Contents)
=> ln(path=/etc/apache2/sites-enabled, src=/etc/apache2/sites-available/my-website.conf, symbolic=True)
=# service(service=apache2, running=True, restarted=False, reloaded=False, enabled=True, daemon_reload=False,
user_mode=False)
>> *** Starting handler: restart_apache
>> *** Starting handler: restart_apacheu
=> service(service=apache2, running=True, restarted=True, reloaded=False, daemon_reload=False, user_mode=False)
>> *** Done with handlers

Expand All @@ -257,6 +257,36 @@ directory.

## Templates

Your playbooks can include Jinja2 template files, which are a convenient way to provide
configuration files and similar. When you `fs.cp()` files with the "template" argument
set to True (the default), the files are rendered using Jinja2, and pick up values from
the uplaybook variables.

uPlaybook includes some "magic" that causes variables in your playbooks, arguments, and
[platform special variables](templating/#platform-info).

For example, if you have a "setup.conf.j2":

```
{% if platform.release_id == 'ubuntu' %}
memory = {{ ((platform.memory_total / 1024) * 0.5) | int}})
{% endif %}
```

And your playbook has:

```python
fs.cp(src="setup.conf.j2", path="/etc/myservice/setup.conf")
```

Then on the ubuntu platform, the file will contain (on a system with 32GB of memory):

```
memory = 16000
```

(or so).

## Playbook Search Path

## Playbook Documentation
Expand Down
4 changes: 3 additions & 1 deletion uplaybook/internals.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ class PasswordNeeded(Exception):

def PlatformInfo() -> types.SimpleNamespace:
"""
See "docs/templating.md#platform_info" for more information.
See
[Platform Info in docs/templating.md](../../templating/#platform-info)
for more information.
"""
env = types.SimpleNamespace()
uname = platform.uname()
Expand Down

0 comments on commit 9b6c2fd

Please sign in to comment.