ansible * when * say:“评估条件时出错”

时间:2016-04-01 06:08:01

标签: ansible

我尝试做类似的事情:

我有这个剧本

---
- hosts: all 
  vars:
    user: myuser
    venv_name: venv
    only_deploy_code: "yes"
  roles:
    - my_venv

在roles / my_venv / tasks / main.yml ::

---
- name: pip Install packages into virtualenv
  pip: name={{ item }} virtualenv="{{ home }}/{{ venv_name }}" virtualenv_site_packages="yes"
  with_items:
    - PyYAML
    - numexpr
  sudo_user: "{{ user }}"
  sudo: true
  when: only_code_deploy == "no"

但我收到此错误::

TASK: [akd_venv | pip Install packages into virtualenv]   
*********************** 
fatal: [vagrant] => error while evaluating conditional: only_code_deploy == "no"

1 个答案:

答案 0 :(得分:1)

尝试省略yes周围的引号并更改when语句,如下所示:

- hosts: all
  gather_facts: no
  vars:
   only_deploy_code: yes
  tasks:
    - debug:
        msg: "This is yes message"
      when: not only_deploy_code

在本地计算机上测试过:

ansible-playbook -i "localhost," test.yml -c local

输出:

PLAY ***************************************************************************

TASK [debug] *******************************************************************
skipping: [localhost]

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

我认为这是您想要的预期行为,只是修改了when语句,如果您想要跳过no而不是yes,请执行以下操作:

when: only_deploy_code