Skip to content

Commit

Permalink
Update README with registered variables usage
Browse files Browse the repository at this point in the history
Expanded on the README by adding a section which explains the usage of registered variables. This section contains details on how registered variables can be used across multiple tasks within the same playbook, with an included example for clarity.
  • Loading branch information
umputun committed Apr 27, 2024
1 parent 0493f2f commit 29d5333
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,27 @@ commands:
copy: {src: $FILE_NAME, dest: /tmp/file2}
```

Another unique feature of the registered variables is that they can be used not only in the subsequent commands for the current task but also in the subsequent tasks. This allows users to pass variables between tasks. In other words, the registered variables are populated to the environment of all the tasks in the playbook, automatically.

example:

```yaml
tasks:
- name: set_register_var
commands:
- name: some command
script: |
echo good command 1
len=$(echo "file content" | wc -c)
register: [len]

- name: use_register_var
commands:
- name: some command
script: |
echo "len: $len"
```

### Setting environment variables

Environment variables can be set with `--env` / `-e` cli option. For example: `-e VAR1:VALUE1 -e VAR2:VALUE2`. Environment variables can also be set in the environment file (default `env.yml` can be changed with `--env-file` / `-E` cli flag). For example:
Expand Down

0 comments on commit 29d5333

Please sign in to comment.