Ansible date variable

后端 未结 5 1681
醉酒成梦
醉酒成梦 2020-12-29 01:21

I\'m trying to learn how to use Ansible facts as variables, and I don\'t get it. When I run...

$ ansible localhost -m setup

...it lists all

5条回答
  •  孤城傲影
    2020-12-29 01:31

    I tried the lookup('pipe,'date') method and got trouble when I push the playbook to the tower. The tower is somehow using UTC timezone. All play executed as early as the + hours of my TZ will give me one day later of the actual date.

    For example: if my TZ is Asia/Manila I supposed to have UTC+8. If I execute the playbook earlier than 8:00am in Ansible Tower, the date will follow to what was in UTC+0. It took me a while until I found this case. It let me use the date option '-d \"+8 hours\" +%F'. Now it gives me the exact date that I wanted.

    Below is the variable I set in my playbook:

      vars:
        cur_target_wd: "{{ lookup('pipe','date -d \"+8 hours\" +%Y/%m-%b/%d-%a') }}"
    

    That will give me the value of "cur_target_wd = 2020/05-May/28-Thu" even I run it earlier than 8:00am now.

提交回复
热议问题