4

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

4
  • You're running with -i staging, but I your inventory file is actually called inventory...
    – larsks
    Mar 27, 2016 at 15:12
  • thanks that was the issue.. I must of read it wrong where i thought inventory was auto searched in the directory.
    – Mike
    Mar 27, 2016 at 17:42
  • No, really, it should work as you initially wanted. I'm not sure about older versions, but 2.1.0 certainly does read inventory file if -i points to a directory containing it.
    – techraf
    Mar 28, 2016 at 3:37
  • ok I'm still using 1.9
    – Mike
    Mar 28, 2016 at 3:43

1 Answer 1

1

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:

ansible-playbook -i staging/inventory test.yml

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .