- name: Get timezone info
shell: date
register: zoneinfo- name: Print zoneinfo for debug
debug: var="zoneinfo.stdout"
TASK: [common | Print zoneinfo for debug] *************************************
ok: [10.10.10.10] => {
"zoneinfo.stdout": "Tue Dec 30 14:11:03 CST 2014"
}- name: If timezone is not CST then remove /etc/localtime and call set timezone handler
file: path=/etc/localtime state=absent
when: zoneinfo.stdout.find('CST') != 1
notify:
- set timezoneHi
For substring comparisons, I use the ‘in’ keyword like this:
- name: Get timezone info
shell: date
register: zoneinfo
changed_when: no
- name: If timezone is not CST then remove /etc/localtime and call set timezone handler
file: path=/etc/localtime state=absent
when: '"CST" in zoneinfo.stdout'
notify: set timezone
The entire conditional is quoted in order to conform to yaml syntax. You could also add changed_when: no to the first task that runs date, so that Ansible doesn’t report it as a changed task.
In this case, I would probably use a task rather than a handler for ‘set timezone’ - should your playbook run fail, the handler will not be invoked and the timezone will not get configured.
Regards
Tom
--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/1c7a5e23-6375-4136-9b75-38777dbf1e41%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CAAnNz0M3oPZ4TYuNMRDsEQmoA42o%2BuVWQZYVjL-Kq_rAYzXj-w%40mail.gmail.com.