On Wednesday, June 22, 2022 8:59:12 AM CDT Aleksandra Fedorova wrote:
On Wed, Jun 22, 2022 at 12:56 PM Miro Hrončok
<mhroncok(a)redhat.com> wrote:
> Hello,
>
> please bare with me because my Ansible skills are close to none. I only
> use
> it for Fedora CI.
No problem. I'm happy to help :).
Vars can be defined on the same level as roles and hosts:
- hosts: localhost
vars:
pybasever: 3.11
roles:
- role: standard-test-basic
...
You can also add variables in the `roles:` section.
```
roles:
- role: role_name_here
var1: ...
var2: ...
```
In your existing tests.yml, all of the key-value pairs in `roles:` besides
`tags` and `role` are variables that are passed to the role. So, you can do
```
- hosts: localhost
roles:
- role: standard-test-basic
tags: ...
repositories: ...
[...]
pybasever: "3.11"
required_packages:
- "python3{{ pybasever }}"
- "python3{{ pybasever }}-devel"
# Or equivalently:
- hosts: localhost
roles:
- role: standard-test-basic
tags: ...
vars:
repositories: ...
pybasever: "3.11"
required_packages:
- "python3{{ pybasever }}"
- "python3{{ pybasever }}-devel"
```
In this case, it doesn't really matter at which level or in what order you
define the variables, as variables are (re)evaluated each time they're used in
a task. I just wanted to provide you some more context :).
Also, keep in mind that, if you're using jinja2 expressions
(e.g. {{ variable | filter }}), that you need to quote the whole expression so
that it's valid yaml. See
https://docs.ansible.com/ansible/latest/user_guide/
playbooks_variables.html#when-to-quote-variables-a-yaml-gotcha for a better
explanation than I can give ;).
"{{ lookup('env', 'TEST_SUBJECTS') }}"
Yes, this is the correct way to look up an env variable. I'm not familiar with
Fedora CI, so I wouldn't know if that's the best way to get the package name.
--
Thanks,
Maxwell G (@gotmax23)
Pronouns: He/Him/His