m1ndgames
m1ndgames

Reputation: 1

Accessing variable from dict by suppling a variable to a playbook

I have the following dict:

webpaket:
  "001":
    projekt: "Test"
    domain: "testdomain.de"
    subdomain: "test"
    fqdn: "test.testdomain.de"
    serveradmin: "[email protected]"
    ip: "*"
    ssl: "true"
    password: "somepass"
    vhost: ""
    symfony: "true"
    localdb: "true"
    clusterdb: "false"
    localdb_pgsql: "false"

This is the playbook:

---
# file: webpaket-remove.yml
- hosts: all
  vars:
    removeweb: "{{ webpaket[webid] }}"
  roles:
    - { role: webpaket-remove, stage: 'dev' }

This is the task:

---
    - name: Delete Web-Directory for {{ webid }}
      file: path=/test/{{ item.value }} state=absent
      with_dict: "{{removeweb}}"

Id like to access a variable from it by giving an argument to ansible playbook like so:

ansible-playbook -l testserver.de --check --diff webpaket-remove.yml --extra-vars "webid=001"

When i run it i get this output:

ok: [testserver.de] => (item={'key': 'projekt', 'value': 'Test'})
ok: [testserver.de] => (item={'key': 'domain', 'value': 'testdomain.de'})

How can i access a keys value?

if i use item.value.projekt i get: "The task includes an option with an undefined variable. The error was: 'projekt' is undefined

item[projekt] also doesent work, im out of ideas here :/

Upvotes: 0

Views: 49

Answers (1)

Vladimir Botka
Vladimir Botka

Reputation: 67984

removeweb isn't a directory. projekt shall be addressed directly

- file:
    path: "/test/{{ removeweb['projekt'] }}"
    state: absent

Upvotes: 1

Related Questions