Skip to content

Instantly share code, notes, and snippets.

@konstruktoid
Last active March 6, 2024 09:00
Show Gist options
  • Save konstruktoid/e55de7f6a07d08e5d9b980d6cda587aa to your computer and use it in GitHub Desktop.
Save konstruktoid/e55de7f6a07d08e5d9b980d6cda587aa to your computer and use it in GitHub Desktop.
$ cat test.yml
---
- name: Testing
hosts: localhost
any_errors_fatal: true
gather_facts: false
tasks:
- name: Set sysctl configuration directory as fact
block:
- name: Stat /usr/lib/sysctl.d/ exists
ansible.builtin.stat:
path: /usr/lib/sysctl.d/
register: usr_lib_sysctl_d
- name: Set sysctl fact
ansible.builtin.set_fact:
sysctl_conf_dir: "{{ '/usr/lib/sysctl.d' if usr_lib_sysctl_d.stat.exists else '/etc/sysctl.d' }}"
- name: Print sysctl conf dif
ansible.builtin.debug:
msg:
- "{{ sysctl_conf_dir }}"
$ ansible-playbook -i '127.0.0.1,' -c local test.yml
[...]
TASK [Print sysctl conf dif] ***************************************************************************
Wednesday 06 March 2024 08:59:23 +0000 (0:00:00.014) 0:00:00.278 *******
ok: [127.0.0.1] => {
"msg": [
"/usr/lib/sysctl.d"
]
}
[...]
$ ansible-playbook -i '127.0.0.1,' -e "sysctl_conf_dir=/some/other" -c local test.yml
[...]
TASK [Print sysctl conf dif] ***************************************************************************
Wednesday 06 March 2024 08:59:27 +0000 (0:00:00.013) 0:00:00.280 *******
ok: [127.0.0.1] => {
"msg": [
"/some/other"
]
}
[...]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment