Skip to content

Commit

Permalink
Add docs for newer ansible features
Browse files Browse the repository at this point in the history
  • Loading branch information
wendrul committed Oct 25, 2024
1 parent ec3e1c4 commit 6a94618
Showing 1 changed file with 50 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ inventory:

# File resources will be written in the relative \`target\` location before
# running the playbook
file_resources:
files:
- resource: u/user/fabulous_jinja_template
target: ./config_template.j2

Expand Down Expand Up @@ -164,6 +164,16 @@ extra_vars:
The type definition is inspired and tries to follow the [OpenAPI Data Types standard](https://swagger.io/docs/specification/data-models/data-types/). Note that not all features / types are supported, the best way to know what is supported is to test it out in the Web IDE.
:::tip Argument defaults
You can set a default value for your arguments by using a `default:` field, for example:
```yml
extra_vars:
my_string:
type: string
default: 'Fascinating String of Words'
```
:::

To use windmill resources as types you can use the following type definition:

```yaml
Expand All @@ -175,7 +185,28 @@ extra_vars:

![Postgres Resource UI](./postgres_ui.png)

Under the hood, Windmill will pass these variables using the `--extra-args` flag to Ansible, so you can expect the according behavior.
Under the hood, Windmill will pass these variables using the `--extra-vars` flag to Ansible, so you can expect the according behavior.

### Static resources and variables

Resources and variables that are hardcoded to a particular script can also be defined in the `extra-vars` section. This is because they are similarly passed through the `--extra-vars` flag in the ansible playbook.

This is what the syntax looks like:
```yml
extra_vars:
my_variable:
type: windmill_variable
variable: u/user/my_variable
my_resource:
type: windmill_resource
resource: u/user/my_resource
```

Under `resource` or `variable` you can statically link the path to the resource/variable. As you do, you will notice the UI update and hide the resource input as it is now static.

:::tip About static and non-static variables
Note that Variables defined this way can only be static. If you want to use non-static Variables, define a normal argument with `type: string` and from the UI fill it with one of your Variables or Secrets.
:::

### Return Values

Expand Down Expand Up @@ -227,7 +258,7 @@ Then the UI will not prompt you for the inventory but will use this resource at
It sometimes happens that your Ansible playbook depends on some text file existing at a relative path to the playbook. This can be a configuration file, a template, some other file that you can't inline or otherwise is simpler to keep as a separate file. In this case, Windmill offers a feature to create these files at the specified path before running the playbook. The syntax will be the following:

```yaml
file_resources:
files:
- resource: u/user/fabulous_jinja_template
target: ./config_template.j2
```
Expand All @@ -236,7 +267,22 @@ To create text file resource type and resources, refer to [creating plain text r

In the example above, the resource `u/user/faboulous_jinja_template` is a special plain text file resource. The target `./config_template.j2` is the path relative to the playbook where the file will be created and where the playbook can access it.

Now you can write your notebook assuming that this file will exist at the time of execution.
Now you can write your playbook assuming that this file will exist at the time of execution.

#### Variable inside files

If you want to achieve a similar effect with a variable or a secret, you can use a similar syntax:

```yaml
files:
- resource: u/user/my_ssh_key
target: ./id_rsa
```

And the content of the variable will be written to the file.

This is useful when you want to store the data in a secret for example, like you would do for ssh keys.


### Dependencies

Expand Down

0 comments on commit 6a94618

Please sign in to comment.