А - да. Б - идёт автоматом если верная группа хостов
Пока получается так:
# /group_vars/mysql
ufw_vars:
- { port: "3306", protocol: "tcp", policy: "allow", from: "any", comment: "allow incoming connection on standard MySQL port" }
# /group_vars/web
ufw_vars:
- { port: "80", protocol: "tcp", policy: "allow", from: "any", comment: "allow incoming connection on standard HTTP port" }
- { port: "443", protocol: "tcp", policy: "allow", from: "any", comment: "allow incoming connection on standard HTTPS port" }
Делаю debug:
- debug:
msg: '{{ ufw_vars }}'
- debug:
msg: '{{ ufw_vars.port }}'
- debug:
msg: '{{ ufw_vars.protocol }}'
Получил следующее:
ok: [ansible5] => {
"msg": [
{
"comment": "allow incoming connection on standard HTTP port",
"from": "any",
"policy": "allow",
"port": "80",
"protocol": "tcp"
},
{
"comment": "allow incoming connection on standard HTTPS port",
"from": "any",
"policy": "allow",
"port": "443",
"protocol": "tcp"
}
]
}
ok: [ansible6] => {
"msg": [
{
"comment": "allow incoming connection on standard MySQL port",
"from": "any",
"policy": "allow",
"port": "3306",
"protocol": "tcp"
}
]
}
А вот получить значение ufw_vars.port и ufw_vars.protocol не получилось:
FAILED! => {"msg": "The task includes an option with an undefined variable. The error was: 'list object' has no attribute 'port'\n\nThe error appears to be in '/home/ansible/ansible_test/ufw.yml': line 34, column 7, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n - debug:\n ^ here\n"}