diff --git a/site/docs/index.md b/site/docs/index.md index fd4c8cf..dd3f450 100644 --- a/site/docs/index.md +++ b/site/docs/index.md @@ -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: diff --git a/spot.1 b/spot.1 index 39e5c5c..9d32d02 100644 --- a/spot.1 +++ b/spot.1 @@ -1,4 +1,4 @@ -.TH "SPOT" 1 20240422T175052 spot manual +.TH "SPOT" 1 20240427T195838 spot manual .\" Automatically generated by Pandoc 3.1.13 .\" .SH Spot @@ -827,6 +827,32 @@ commands\f[B]:\f[R] \f[B]\-\f[R] name\f[B]:\f[R] third command copy\f[B]:\f[R] \f[B]{\f[R]src\f[B]:\f[R] $FILE_NAME\f[B],\f[R] dest\f[B]:\f[R] /tmp/file2\f[B]}\f[R] .EE +.PP +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. +.PP +example: +.IP +.EX +tasks\f[B]:\f[R] + \f[B]\-\f[R] name\f[B]:\f[R] set_register_var + commands\f[B]:\f[R] + \f[B]\-\f[R] name\f[B]:\f[R] some command + script\f[B]: \f[R]| + echo good command 1 + len=$(echo \[dq]file content\[dq] | wc \-c) + register\f[B]:\f[R] \f[B][\f[R]len\f[B]]\f[R] + + \f[B]\-\f[R] name\f[B]:\f[R] use_register_var + commands\f[B]:\f[R] + \f[B]\-\f[R] name\f[B]:\f[R] some command + script\f[B]: \f[R]| + echo \[dq]len: $len\[dq] +.EE .SS Setting environment variables Environment variables can be set with \f[CR]\-\-env\f[R] / \f[CR]\-e\f[R] cli option.