2016-07-13 12 views
1

Meine Probe Textbuch (für ansible 2.1) ist:Standardwert für ansible Hosts in Playbook?

--- 
# This is sample playbook. 

- name: add sample_role 
    hosts: '{{ target }}' 
    become: true 
    become_user: root 
    roles: 
    - sample role 

Wenn ich es laufen, alles ist in Ordnung:

ansible-playbook -i staging test_playbook.yml --extra-vars "target=192.168.15.29" 

Wie kann ich Ziele weglassen?

Ich habe so etwas wie dies versucht:

hosts: '{{ target | default(all) }}' 

oder

hosts: '{{ target | default(hostvars) }}' 

dann laufen:

ansible-playbook -i staging test_playbook.yml 

, aber leider:

FEHLER! 'All' ist

undefined

oder:

ERROR! ‚Hostvars‘ ist

undefined

Antwort

3

Wenn Sie einfach die all ohne Zitat fügen Sie dann nehmen sie es als Variable, so können Sie es wie folgt festgelegt:

hosts: '{{ target | default("all") }}'

Was hostvars es ist ein reserviertes Wort in ansible und kann es nicht für diesen Zweck verwenden, denke ich. Es wird Wert in etwa so sein:

ok: [localhost] => { 
    "msg": { 
     "localhost": { 
      "ansible_check_mode": false, 
      "ansible_version": { 
       "full": "2.1.0.0", 
       "major": 2, 
       "minor": 1, 
       "revision": 0, 
       "string": "2.1.0.0" 
      }, 
      "group_names": [], 
      "groups": { 
       "all": [ 
        "localhost" 
       ], 
       "ungrouped": [] 
      }, 
      "inventory_dir": null, 
      "inventory_file": null, 
      "inventory_hostname": "localhost", 
      "inventory_hostname_short": "localhost", 
      "omit": "__omit_place_holder__41c600ef78930ed8b38e6eed4e5b5ab51199729e", 
      "playbook_dir": "/Users/xyz/test-ansible" 
     } 
    } 
} 

Ich hoffe, dass Ihnen helfen.

+0

Doppelzitate um 'all' funktionieren für mich:' '' 'hosts: '{{target | Standard ("alle")}} ''' '' –

Verwandte Themen