Cant call hostvars variables from a task in a role

27 views
Skip to first unread message

Leandro Reox

unread,
Oct 29, 2014, 5:05:54 PM10/29/14
to ansible...@googlegroups.com
Folks, 

Were dealing with some weird issue that we want to clarify, clearly were understanding something wrong

Heres is our current playbook distribution, with roles and stuff

deploy/
├── ansible.cfg
├── filter_plugins
│   ├── search_hostvars.py
│   └── search_hostvars.pyc
├── group_vars
│   ├── all
├── install_ansible.sh
├── inventory
│   └── inventory
├── openstack.yaml
├── roles
│   ├── apt-cacher
│   │   ├── defaults
│   │   │   ├── main.yaml
│   │   │   └── trackfile
│   │   ├── files
│   │   │   └── trackfile
│   │   ├── handlers
│   │   │   └── trackfile
│   │   ├── meta
│   │   │   └── trackfile
│   │   ├── tasks
│   │   │   ├── main.yaml
│   │   │   └── trackfile
│   │   ├── templates
│   │   │   ├── etc
│   │   │   │   └── apt
│   │   │   │       └── apt.conf.d
│   │   │   │           └── 000apt-cacher-ng-proxy
│   │   │   └── trackfile
│   │   ├── trackfile
│   │   └── vars
│   │       ├── main.yaml
│   │       └── trackfile


In the apt-cacher role task main.yaml we have : 

---

  - name: update apt cache
    sudo: yes
    apt:
      update_cache: yes

  - name: Display all variables/facts known for a host
    sudo: yes
    debug: var=hostvars

  - name: Configure APT to use cache server if available
    sudo: yes
    template: src=etc/apt/apt.conf.d/000apt-cacher-ng-proxy dest=/etc/apt/apt.conf.d/000apt-cacher-ng-proxy owner=root group=root mode=0644

  - name: Install apt-cacher-ng on cache server
    sudo: yes
    apt: pkg=apt-cacher-ng state=latest install_recommends=no

In this scenario hostvars is printed ok, BUT if we try to call some value INSIDE hostvars, it fails with template failed expected "," got "CHAR"  

For example    - debug: msg="{{ hostvars['rabbithost'] }}" and the KEY is present and we see it OK on on the dict when we print hostvars

What its the way to call hostvars variables from a task in a role and access the whole hostvars tree just fine ?

Best




Reply all
Reply to author
Forward
0 new messages