我有一个URI模块调用带有启动时间和结束时间的api。
- name: silence alert of a specific hostname
uri:
url: localhost:8080/alert-manager/api/v2/silences
method: POST
HEADER_Content-Type: "application/json"
return_content: yes
body:
matchers:
- name : "hostname"
value : "{{ remotehost_output.stdout}}"
isRegex: false
startsAt: "{{ '%Y-%m-%dT%H:%M:%S' | strftime( ( ansible_date_time.epoch | int ) ) }}"
endsAt : "{{ '%Y-%m-%dT%H:%M:%S' | strftime( ( ansible_date_time.epoch | int ) + ( 3600 * 2 ) ) }}"
createdBy : "punith bp"
comment: "via ansible"
body_format: json
status_code: 200
我需要从变量中发送数个小时,即在这一行中
endsAt : "{{ '%Y-%m-%dT%H:%M:%S' | strftime( ( ansible_date_time.epoch | int ) + ( 3600 * 2 ) ) }}"
我需要发送一个包含该变量的变量,而不是“2”。先谢了,我是新来的。
发布于 2022-04-27 12:58:27
试试这个
- hosts: localhost
tasks:
- debug:
msg: "{{ '%Y-%m-%dT%H:%M:%S' | strftime( ( ansible_date_time.epoch | int ) + ( 3600 * hours | int) ) }}"
vars:
hours: 2
我拿到了这根木头
PLAY [localhost] *******************************************************************************
TASK [Gathering Facts] *************************************************************************
ok: [localhost]
TASK [debug] ***********************************************************************************
ok: [localhost] => {
"msg": "2022-04-27T16:59:02"
}
PLAY RECAP *************************************************************************************
localhost : ok=2 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
https://stackoverflow.com/questions/72028495
复制相似问题