The use-case here is that based on information in the /proc/cmdline certain actions can be taken.
A practical example in our case is that we have a play at the end of the provisioning phase that reboots the system. Since we don't want to accidentally reboot a system (or restart the network) on a production machine, having a way to separate an Anaconda post-install (sshd in chroot) with a normal system is a good way to make that distinction.
---
- name: reboot
hosts: all
tasks:
- action: command init 6
only_if: "not '${ansible_cmdline.BOOT_IMAGE}'.startswith('$')"
A practical problem here is the fact that we cannot simply check whether it is set or empty:
---
- name: reboot
hosts: all
tasks:
- action: command init 6
only_if: "'${ansible_cmdline.BOOT_IMAGE}'"
If ansible_cmdline was a string, a simple only_if: "'${ansible_cmdline}'.find(' BOOT_IMAGE=')" was an option, but still not very "beautiful" :-/
This implementation uses shlex.split() and uses split(sep, maxsplit=1).
| Name |
Last commit
|
Last update |
|---|---|---|
| .. | ||
| apt | Loading commit data... | |
| apt_repository | Loading commit data... | |
| assemble | Loading commit data... | |
| async_status | Loading commit data... | |
| async_wrapper | Loading commit data... | |
| authorized_key | Loading commit data... | |
| command | Loading commit data... | |
| copy | Loading commit data... | |
| easy_install | Loading commit data... | |
| facter | Loading commit data... | |
| fetch | Loading commit data... | |
| file | Loading commit data... | |
| get_url | Loading commit data... | |
| git | Loading commit data... | |
| group | Loading commit data... | |
| lineinfile | Loading commit data... | |
| mount | Loading commit data... | |
| mysql_db | Loading commit data... | |
| mysql_user | Loading commit data... | |
| nagios | Loading commit data... | |
| ohai | Loading commit data... | |
| ping | Loading commit data... | |
| pip | Loading commit data... | |
| postgresql_db | Loading commit data... | |
| postgresql_user | Loading commit data... | |
| raw | Loading commit data... | |
| seboolean | Loading commit data... | |
| selinux | Loading commit data... | |
| service | Loading commit data... | |
| setup | Loading commit data... | |
| shell | Loading commit data... | |
| slurp | Loading commit data... | |
| subversion | Loading commit data... | |
| supervisorctl | Loading commit data... | |
| template | Loading commit data... | |
| user | Loading commit data... | |
| virt | Loading commit data... | |
| wait_for | Loading commit data... | |
| yum | Loading commit data... |