I write a role. In defaults/main.yml I have:
sysctl:
net.inet.ip.forwarding: 1
vm.swappiness: 10
tasks/main.yml:
- name: Setup sysctl.conf
sysctl: name="{{ item.0 }}" value="{{ item.1 }}" state=present
become: yes
loop: "{{ sysctl_default | combine(sysctl) | dictsort }} "
If user doesn't define sysctl
in vars ansible will raise an error. Default parameters must be set if user skip this settings. How to create empty dictionary if user ommit sysctl settings in his playbook? Such expression {{ sysctl_default | combine(sysctl | default({})) | dictsort }}
doesn't working:
fatal: [192.168.140.96]: FAILED! => {"msg": "|combine expects dictionaries, got AnsibleUndefined"}
when
clause in your task, to check if thesysctl
variable is defined and has items. by adding a default filter, what are you planning to achieve? run thesysctl
task without a valid change to do? – ilias-spnet.inet.ip.forwarding: 1
by default, because this role is for router. So, even if user skip this setting it will be ok, the role take care of it explicitly :) – dynax60