I am new to ansible.
I create a yaml file with multiple hosts defined
Look for group vars and put all servers in the same group in the inventory file.
Is there a way to do it in the same playbook where I define my tasks? I do not have an inventory file.
If the variables you want to share between plays is static it’s more straight forward to use and group_vars file.
The group_vars file doesn’t have to be inside the inventory folder. It can be in a group_vars folder on the same level as your playbook
If you really cannot afford an inventory file and a group_vars file then have a look at https://stackoverflow.com/a/47811099
group_vars can be playbook adjacent, they do not require an inventory
(though they normally work better with one).
You can also use `-e @varsfile.yml ` on the command line to add extra vars
Another option is to define them in a vars/myvars.yml and use
vars_files: in each play to include them, instead of repeating them.