Ansible not allowing environment at playbook level

2019-07-16 03:57发布

问题:

I'm having issues defining environment variables at playbook level. According to the docs it should be possible.

$ ansible --version
1.7.1

$ ansible-playbook -i staging deploy.yml
ERROR: environment is not a legal parameter at this level in an Ansible Playbook

Here's the playbook simplified:

---
- hosts: app
  user: web

  environment:
    PATH: "{{ path_append }}:{{ ansible_env.PATH }}"

  tasks:
    - ...
    - ...

Just to make sure, I tried setting it without the variables, and the result was equal.

Moving the environment-definition inside the tasks works.

回答1:

The doc was incorrect. It was a bug which was fixed in a later version (ansible 1.8). Can you upgrade to 1.9.x?

Enable environment keyword at play level