I'm trying to organize ansible from a ssh model to pull. Before I had a setup like
group_vars/
all
prod
stage
dev
Now I'm trying to run everything via cron so I tried this setup
staging/
inventory
group_vars/
server
prod/
inventory
group_vars/
server
inventory on both look like
[server]
localhost ansible_connection=local
for stage my group_vars look like
---
rails_env: staging
I have an example play
- hosts: server
user: root
sudo: no
gather_facts: True
tasks:
- debug: msg="reading from {{ rails_env }}"
My run output is
# ansible-playbook -i staging test.yml
PLAY [server] *****************************************************************
GATHERING FACTS ***************************************************************
ok: [localhost]
TASK: [debug msg="reading from {{ rails_env }}"] ******************************
fatal: [localhost] => One or more undefined variables: 'rails_env' is undefined
FATAL: all hosts have already failed -- aborting
PLAY RECAP ********************************************************************
to retry, use: --limit @/root/test.retry
localhost : ok=1 changed=0 unreachable=1 failed=0
Not sure what I'm doing wrong as it should pick that up
In version 1.9 you can't do that, on stable version 2.0.2.0 doesn't work either. You should read this: http://docs.ansible.com/ansible/playbooks_best_practices.html . I suggest running like this: