# Put anisble up and running example in a role with add\_host

**URL:** <https://forum.ansible.com/t/put-anisble-up-and-running-example-in-a-role-with-add-host/23944>\
**Category:** Ansible Project\
**Created:** [March 12, 2017, 4:33am UTC](https://forum.ansible.com/t/put-anisble-up-and-running-example-in-a-role-with-add-host/23944 "2017-03-12T04:33:54Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Zhu\_Wayne](https://avatars.discourse-cdn.com/v4/letter/z/ecc23a/32.png) [@Zhu\_Wayne](https://forum.ansible.com/u/Zhu_Wayne)\
**Post date:** [March 12, 2017, 4:33am UTC](https://forum.ansible.com/t/put-anisble-up-and-running-example-in-a-role-with-add-host/23944/1 "2017-03-12T04:33:54Z")

</div>

```auto
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:

```

```auto
        box: trusty64
      tasks:

```

```auto
        - name: create a Vagrantfile
          command: vagrant init {{ box }} creates=Vagrantfile

```

```auto
        - name: Bring up a vagrant server
          command: vagrant up

```

```auto
        - name: add the Vagrant hosts to the inventory
          add_host: >

```

```auto
                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
 

```

```auto
    - name: Do something to the vagrant machine
      hosts: vagrant
      sudo: yes
      tasks:

```

---

<div class="post-metadata">

**Author:** ![Dick\_Davies](https://avatars.discourse-cdn.com/v4/letter/d/b9e5f3/32.png) [@Dick\_Davies](https://forum.ansible.com/u/Dick_Davies)\
**Post date:** [March 12, 2017, 9:32pm UTC](https://forum.ansible.com/t/put-anisble-up-and-running-example-in-a-role-with-add-host/23944/2 "2017-03-12T21:32:29Z")

</div>

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.
