Zhu_Wayne
(Zhu Wayne)
March 12, 2017, 4:33am
1
Is it possible to pack the following into a single role? My understanding that a role ONLY can be run on a defined set of hosts.
- name: Provision a vagrant machine
hosts: localhost
vars:
box: trusty64
tasks:
- name: create a Vagrantfile
command: vagrant init {{ box }} creates=Vagrantfile
- name: Bring up a vagrant server
command: vagrant up
- name: add the Vagrant hosts to the inventory
add_host: >
name=vagrant
ansible_ssh_host=127.0.0.1
ansible_ssh_port=2222
ansible_ssh_user=vagrant
ansible_ssh_private_key_file=/Users/lorinhochstein/.vagrant.d/
insecure_private_key
- name: Do something to the vagrant machine
hosts: vagrant
sudo: yes
tasks:
You could use delegation to run some of the tasks on another machine
(in this case localhost).
But to be honest I wouldn't, personally I'd split this into 2 plays.