I'm configuring Ansible role to install a specific Nginx version. This is the folder structure:
nginx
├── defaults
│ └── main.yml
├── handlers
│ └── main.yml
├── molecule
│ └── default
│ ├── collections.yml
│ ├── converge.yml
│ ├── molecule.yml
│ └── verify.yml
├── tasks
│ └── main.yml
└── templates
├── nginx.j2
└── nginx.repo
Now I have two problems:
- How can define
nginx_packagevariable usingversionvariable?
---
defaults:
user: nginx
group: nginx
version: 1.19.2
#nginx_package: nginx-1.19.2-1.el7.ngx
nginx_package: nginx-{{defaults.version}}-1.el7.ngx
OS: centos
OSRELEASE: 7
- Can I (and how can) use a variable
versioninto the filemolecule\default\verify.yml
Thanks for the support.
nginx_package: nginx-{{version}}-1.el7.ngxdefaults:dict will make it difficult to work with individual key-pairs inside it. Better to keep each role default variable separate, i.e.nginx_user: nginx,nginx_group: nginx, etc,nginx_package: nginx-{{version}}-1.el7.ngxbut I receive this error:FAILED! => {"msg": "The task includes an option with an undefined variable. The error was: {'version': '1.19.2', 'nginx_package': 'nginx-\"{{ version }}\"-1.el7.ngx', 'version' is undefineddefaultsstructure.defaultsdict. Values within the dict structure can not be cross-referenced.nginx_package: nginx-{{defaults.version}}-1.el7.ngxwill work when you put it outsidedefaults:.