Ubuntu Ansible中的寄存器变量

Ubuntu Ansible中的寄存器变量,ubuntu,ansible,Ubuntu,Ansible,嗨,我是Ansible的新手,在使用注册变量时遇到了一些问题 问题是,我有多台服务器,使用不同的操作系统 我使用角色来分隔它们,但在没有一种服务器的情况下 一个条件给了我一个错误,说明我必须将一个表达式的计算结果设置为True或False 这是有问题的代码 - name: Checking if Sources are Available action: shell echo a$(cat /etc/apt/sources.list | grep $(echo 'http://url

嗨,我是Ansible的新手,在使用注册变量时遇到了一些问题

问题是,我有多台服务器,使用不同的操作系统

我使用角色来分隔它们,但在没有一种服务器的情况下 一个条件给了我一个错误,说明我必须将一个表达式的计算结果设置为True或False

这是有问题的代码

 - name: Checking if Sources are Available
   action: shell echo a$(cat /etc/apt/sources.list | grep $(echo   'http://url/${ansible_distribution}/stable' | tr "[:upper:]" "[:lower:]"  ))
   register: sources
   ignore_errors: True

 - name: Adding source.
   action: shell echo "deb http://url/${ansible_distribution}/stable      ${ansible_lsb.codename} main" | tr "[:upper:]" "[:lower:]" >> /etc/apt/sources.list
   when: "ansible_os_family == 'RedHat' and sources.stdout == 'a'"
给我的错误是:

fatal: [192.168.1.114] => Conditional expression must evaluate to True or False: ({% if     ansible_os_family == 'RedHat' and sources.stdout == 'a' %} True {% else %} False {% endif   %}) and ({% if ansible_os_family == 'Debian' %} True {% else %} False {% endif %})
fatal: [192.168.1.141] => Conditional expression must evaluate to True or False: ({% if ansible_os_family == 'RedHat' and sources.stdout == 'a' %} True {% else %} False {% endif   %}) and ({% if ansible_os_family == 'Debian' %} True {% else %} False {% endif %})

 FATAL: all hosts have already failed -- aborting
我已经试过这些了: 当:sources.stdout已定义且source.stdout==a时 仅当定义了sources.stdout并且source.stdout==a时

这给了我同样的错误

我正在Ubuntu 13.04中使用Ansible 1.3 为了验证这一点,我使用了ansible--version

希望你能帮助我。
问候语

我在mbp上使用ansible 1.2测试代码,它工作正常:

---
- hosts: local
  tasks:
    - name: Checking if Sources are Available
      action: shell echo a$(cat /etc/apt/sources.list | grep $(echo   'http://url/${ansible_distribution}/stable' | tr "[:upper:]" "[:lower:]"  ))
      register: sources
      ignore_errors: True

    - debug: msg="sources value is ${sources.stdout} "
    - name: Adding source.
      action: shell echo "deb http://url/${ansible_distribution}/stable      ${ansible_lsb.codename} main" | tr "[:upper:]" "[:lower:]" >> /etc/apt/sources.list
      when: "ansible_os_family == 'RedHat' and sources.stdout == 'a'"
结果:

ansible-playbook test.yml

PLAY [local] ******************************************************************

GATHERING FACTS ***************************************************************
ok: [localhost]

TASK: [Checking if Sources are Available] *************************************
changed: [localhost]

TASK: [debug msg="sources value is ${sources.stdout} "] ***********************
ok: [localhost] => {"msg": "sources value is a "}

TASK: [Adding source.] ********************************************************
skipping: [localhost]

PLAY RECAP ********************************************************************
localhost                  : ok=4    changed=1    unreachable=0    failed=0

您可以参考

我在mbp上使用ansible 1.2测试代码,它工作正常:

---
- hosts: local
  tasks:
    - name: Checking if Sources are Available
      action: shell echo a$(cat /etc/apt/sources.list | grep $(echo   'http://url/${ansible_distribution}/stable' | tr "[:upper:]" "[:lower:]"  ))
      register: sources
      ignore_errors: True

    - debug: msg="sources value is ${sources.stdout} "
    - name: Adding source.
      action: shell echo "deb http://url/${ansible_distribution}/stable      ${ansible_lsb.codename} main" | tr "[:upper:]" "[:lower:]" >> /etc/apt/sources.list
      when: "ansible_os_family == 'RedHat' and sources.stdout == 'a'"
结果:

ansible-playbook test.yml

PLAY [local] ******************************************************************

GATHERING FACTS ***************************************************************
ok: [localhost]

TASK: [Checking if Sources are Available] *************************************
changed: [localhost]

TASK: [debug msg="sources value is ${sources.stdout} "] ***********************
ok: [localhost] => {"msg": "sources value is a "}

TASK: [Adding source.] ********************************************************
skipping: [localhost]

PLAY RECAP ********************************************************************
localhost                  : ok=4    changed=1    unreachable=0    failed=0

您可以参考

您可能有:

  gather_facts: false

在您的剧本中?

您可能有:

  gather_facts: false

在你的剧本中?

我认为这与这个问题有关:


在ansible的当前开发版本中似乎已修复。

我认为这与此问题有关:

在ansible的当前开发版本中似乎已修复