Ansible: Include playbook according to inventory variable -


i trying set ansible able run playbook according inventory group host in. example, in inventory, have:

[group1] host1.sub.domain.tld ansible_host=10.0.0.2 ... [group1:vars] whatsmyplaybook=build-server.yml 

then want make simple playbook more or less redirect playbook in inventory:

--- - name: load playbook inventory   include: "{{hostvars[server].whatsmyplaybook}}" 

where "server" variable host's fqdn, passed in command line:

ansible-playbook whatsmyplaybook.yml -e "server=host1.sub.domain.tld" 

our reasoning have server bootstrap fresh installation (pxe boot), know fqdn, have firstboot script ssh our ansible host , kick off above command. however, when this, below error:

error! 'hostvars' undefined 

this suggests inventory not parsed until host list provided, sucks lot. there way accomplish this?

a bit strange workflow, honestly.

your setup doesn't work, because of variables not defined during playbook parse time.

you may more lucky defining single playbook different plays different groups (no need set group var, use correct host pattern (group name in example)) , execute limiting specific host:

site.yml:

--- - hosts: group1   tasks:     - include: build-web-server-tasks.yml  - hosts: group2   tasks:     - include: build-db-server-tasks2.yml 

command provision specific server:

ansible-playbook -l host1.sub.domain.tld site.yml 

Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -