小编saf*_*ron的帖子

在 Ansible Playbook 中将字符串转换为整数

我从 powershell 命令获取计数并将其注册到变量上。我必须在 when 条件下使用该计数。在 when 条件下使用它之前,我已将其更改为 int 。尽管此处的计数为 0,但仍会跳过该任务(邮件通知)。有人可以告诉我我在这里做错了什么。下面是我正在执行的代码

      - name: Get message_count
        shell:  echo "{{ (output.stdout | from_json).MessageCount  }}"
        register: message_count   #message_count is Zero here
        delegate_to: localhost
     
      - set_fact:
          countt: "{{ message_count | int}}"    
Run Code Online (Sandbox Code Playgroud)

#在使用 set_fact 传递给条件之前尝试转换为整数

      - debug: var=countt
      - name: send mail notification
        mail:
           host: abc.zzzz.net
           port: 25
           from: <noreply@controlnode.com>
           to:
           - abc@xyz.com        

           subject: Test mail sent from core server 
           body: Test mail sent from core server        
        delegate_to: localhost
        when: countt==0
Run Code Online (Sandbox Code Playgroud)

ansible ansible-playbook ansible-tower

7
推荐指数
1
解决办法
1万
查看次数

标签 统计

ansible ×1

ansible-playbook ×1

ansible-tower ×1