Hello community,
I’m a outer playbook like this
- hosts: $SERVER
user: root
connection: ssh
vars_prompt:
- name: “SERVER”
prompt: “\nEnter servername\n”
private: no
tasks:
my inner playbook should be included at the end of the first playbook and should work on the same server. How could I do it at the end?
- hosts: $SERVER
user: ansible
connection: ssh
sudo: yes
By now I couldn’t figure a way out to pass this the Server var to the second playbook?
Any suggestions? or is the hosts var not meant to be passed through playbooks.
Thanks a lot
first, they are plays, playbook is a list of plays, plays cannot include other plays (they must be at same level) but they can include tasks and roles.
you can use the $SERVER variable if you pass it as an extravar -e “SERVER=myhost” this will work for all playbooks included in the same commandline.
you might also want to leave it as a group and use --limit to include/exclude which servers you run against. Also, --list-hosts is good to test what will be targeted.
First off – please do not use $foo.
The new way to do variables, standardized in Ansible is “{{ foo }}”.
This allows much easier access to complex variable data.
If everyone stops saying $foo I will also be able to repeat myself less
yes, you can pass in things via --extra-args like Brian said, but --limit is definitely the preferred way to do this if you are comfortable with the idea that if you leave off --limit it would run on everything. You might not be, in which case, consider the “-e” technique.