# Playbook ansible

**URL:** <https://forum.ansible.com/t/playbook-ansible/4202>\
**Category:** Get Help\
**Created:** [March 4, 2024, 1:31pm UTC](https://forum.ansible.com/t/playbook-ansible/4202 "2024-03-04T13:31:34Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jasonroot1](https://avatars.discourse-cdn.com/v4/letter/j/8491ac/32.png) [@Jasonroot1](https://forum.ansible.com/u/Jasonroot1)\
**Post date:** [March 4, 2024, 1:31pm UTC](https://forum.ansible.com/t/playbook-ansible/4202/1 "2024-03-04T13:31:34Z")

</div>

Good morning, I have a problem with a task, I want to run a playbook that executes different commands on different machines in my inventory, how can I do it?

---

<div class="post-metadata">

**Author:** ![Dustin](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/dustin/32/2573_2.png) [@Dustin](https://forum.ansible.com/u/Dustin)\
**Post date:** [March 4, 2024, 2:55pm UTC](https://forum.ansible.com/t/playbook-ansible/4202/2 "2024-03-04T14:55:05Z")

</div>

There are quiet a few different ways this could be achieved.  
A quick and dirty way you could achieve this would be to store the per-host command in host\_vars, and then execute the command as a task.

```bash
# File: host_vars/your_host/vars
per_host_command: "echo 'Hello, World!'"

```

```yaml
[... Playbook Stuff ...]
  tasks:
    - name: Run Custom Command
      ansible.builtin.command: "{{ per_host_command }}"

```

I’m sure there are much better ways to achieve what you are attempting, but without more information its hard to give a better solution.

---

<div class="post-metadata">

**Author:** ![Jasonroot1](https://avatars.discourse-cdn.com/v4/letter/j/8491ac/32.png) [@Jasonroot1](https://forum.ansible.com/u/Jasonroot1)\
**Post date:** [March 4, 2024, 3:16pm UTC](https://forum.ansible.com/t/playbook-ansible/4202/3 "2024-03-04T15:16:48Z")

</div>

I have a list of servers, these servers must download the services at the same time, but the services are stored in a different route so I have not been able to find a way in which I can run within the same playbook different routes on different servers

---

<div class="post-metadata">

**Author:** ![utoddl](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/utoddl/32/249_2.png) [@utoddl](https://forum.ansible.com/u/utoddl)\
**Post date:** [March 4, 2024, 3:20pm UTC](https://forum.ansible.com/t/playbook-ansible/4202/4 "2024-03-04T15:20:18Z")

</div>

That may be specific enough for someone who already knows what you mean, but it’s very hand-wavey to me. Can you pick a couple of example machines and show us (me) what you need to do differently on each one? I just need something concrete enough to get some clue what’s actually involved.

---

<div class="post-metadata">

**Author:** ![jrglynn2](https://avatars.discourse-cdn.com/v4/letter/j/94ad74/32.png) [@jrglynn2](https://forum.ansible.com/u/jrglynn2)\
**Post date:** [March 4, 2024, 3:38pm UTC](https://forum.ansible.com/t/playbook-ansible/4202/5 "2024-03-04T15:38:42Z")

</div>

Per the “Get help” guidelines:

- Give a clear explanation (and steps to reproduce the issue where possible)
- Include the version(s) of the relevant software tools, libraries, collections etc
- Include relavant logs from the issue
- Use backticks (```) to help format your logs and code (easy-to-read posts are easier to answer too!), like this:

```auto
- my code!

```

- Set at least one tag (the experts follow the tags, so the right people will find you if you tag)

---

<div class="post-metadata">

**Author:** ![Dustin](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/dustin/32/2573_2.png) [@Dustin](https://forum.ansible.com/u/Dustin)\
**Post date:** [March 4, 2024, 5:07pm UTC](https://forum.ansible.com/t/playbook-ansible/4202/6 "2024-03-04T17:07:01Z")

</div>

Just to help me understand, let’s pretend they are all exactly the same. Show me what your playbook task would look like to “download the services”.
