首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何在ansible中的时间变量中添加变量?

如何在ansible中的时间变量中添加变量?
EN

Stack Overflow用户
提问于 2022-04-27 12:11:46
回答 1查看 49关注 0票数 0

我有一个URI模块调用带有启动时间和结束时间的api。

代码语言:javascript
运行
复制
- 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 

我需要从变量中发送数个小时,即在这一行中

代码语言:javascript
运行
复制
              endsAt : "{{ '%Y-%m-%dT%H:%M:%S' | strftime( ( ansible_date_time.epoch | int ) + ( 3600 * 2 )  ) }}"

我需要发送一个包含该变量的变量,而不是“2”。先谢了,我是新来的。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-04-27 12:58:27

试试这个

代码语言:javascript
运行
复制
- hosts: localhost
  tasks:
    - debug:
        msg: "{{ '%Y-%m-%dT%H:%M:%S' | strftime( ( ansible_date_time.epoch | int ) + ( 3600 * hours | int)  ) }}"
      vars:
        hours: 2

我拿到了这根木头

代码语言:javascript
运行
复制
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
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72028495

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档