Put anisble up and running example in a role with add_host

14 views
Skip to first unread message

Zhu Wayne

unread,
Mar 12, 2017, 11:30:23 AM3/12/17
to Ansible Project
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:

Dick Davies

unread,
Mar 12, 2017, 5:32:34 PM3/12/17
to ansible list
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.
> --
> You received this message because you are subscribed to the Google Groups
> "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to ansible-proje...@googlegroups.com.
> To post to this group, send email to ansible...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/e65e7792-1911-4bd7-a773-2c13e08d20dd%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages