# How make an alias resolve accordingly amongst different playbooks?

**URL:** <https://forum.ansible.com/t/how-make-an-alias-resolve-accordingly-amongst-different-playbooks/20496>\
**Category:** Ansible Project\
**Created:** [February 9, 2016, 3:41pm UTC](https://forum.ansible.com/t/how-make-an-alias-resolve-accordingly-amongst-different-playbooks/20496 "2016-02-09T15:41:35Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Manos\_Seferidis](https://avatars.discourse-cdn.com/v4/letter/m/8edcca/32.png) [@Manos\_Seferidis](https://forum.ansible.com/u/Manos_Seferidis)\
**Post date:** [February 9, 2016, 3:41pm UTC](https://forum.ansible.com/t/how-make-an-alias-resolve-accordingly-amongst-different-playbooks/20496/1 "2016-02-09T15:41:35Z")

</div>

I have been fighting with this issue for days. I have been trying to avoid roles, since my setup seems pretty simple.  
Not even sure if roles are needed. You can find this question on [stackoverflow](http://stackoverflow.com/questions/35293566/ansible-how-handle-servers-on-the-same-host) as well.

**My problem**

Here’s my inventory:

```auto
[development]
web_server ansible_connection=docker
db_server ansible_connection=docker

[staging]
web_server ansible_host=20.20.20.20 ansible_user=tom ansible_connection=ssh
db_server ansible_host=20.20.20.20 ansible_user=tom ansible_connection=ssh

[production]
web_server ansible_host=10.10.10.10 ansible_user=tom ansible_connection=ssh
db_server ansible_host=10.10.10.10 ansible_user=tom ansible_connection=ssh

```

My issue now is that I can’t figure a way of having my three playbooks: _production.yml, staging.yml, development.yml_ to resolve the web\_server and db\_server aliases to the appropriate machines. I want to use those aliases throughout my tasks and playbooks for consistency but nothing seems to work.

**Things I’ve tried**

This solution doesn’t work since it runs all tasks twice!

```auto
---
- hosts: staging
  tasks:
    - name: Setup web server
      command: uptime
      delegate_to: web_server
    - name: Setup db server
      command: ls
      delegate_to: db_server
 

```

This solution solves the above problem but it prints the wrong alias (`web_server` even when running the db task).

```auto
---
- hosts: staging
  run_once: true
  tasks:
    - name: Setup web servers
      command: uptime
      delegate_to: web_server
    - name: Setup db servers
      command: ls
      delegate_to: db_server

This solution suggested by someone at stackoverflow doesn't work either (although without errors). web_server and db_server resolve to the wrong machine.

```

```auto
---
- hosts: staging:web_server
  tasks:
    - name: Deploy to web server
      command: uptime
---
- hosts: staging:db_server
  tasks:
    - name: Deploy to db server
      command: ls

```

```auto
This solution would be ideal but Ansible does not support access to an individual host from a group from what I know:

---
- hosts: web_server
  tasks:
    - name: Setup web server
      command: uptime
- hosts: db_server
  tasks:
    - name: Setup db server
      command: ls

```

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [February 9, 2016, 4:40pm UTC](https://forum.ansible.com/t/how-make-an-alias-resolve-accordingly-amongst-different-playbooks/20496/2 "2016-02-09T16:40:07Z")

</div>

I used to do this in 3 inventories production, staging, development, then you can have single play and just use -i /path/to/production on playbooks to choose your environment (ops could also use -i /path/to to point at all servers).
