Use IP in hosts as variables in roles

34 views
Skip to first unread message

Alexandre Grais

unread,
Jul 27, 2015, 6:07:22 PM7/27/15
to Ansible Project
Hi Ansible guys,

I am using ansible to provision my django application composed of:
- A Django Webserver on (Machine A IP : 1.1.1.1)
- A PostgreSQL Database (Machine B IP: 2.2.2.2)
- RabbitMQ Server (Machine C)
- Celery Woekers (Machine D)

[database]
2.2.2.2

[django]
1.1.1.1



The main question I have is the following:
I'm using ansible to generate my settings.py for production. In this file, we need to define the database such as:
########## DATABASE CONFIGURATION
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'toto',  # To be compliant with automatic exports from production
        'USER': 'postgres',
        'PASSWORD': '',
        'HOST': '2.2.2.2',  # MACHINE B IP ADRESS
        'PORT': '5432',
    }
}
########## END DATABASE CONFIGURATION

Right now, I am hard coding the IP of my database in the settings.py file. But I don't feel confortable with this approach. What if I need to deploy an other environment ?  I was wondering how I could get dynamically the IP of my database server and use it as a variable in my differents templates.

If you have any ideas about how to proceed, I would be really happy to hear from you.

Regards.

J Hawkesworth

unread,
Jul 29, 2015, 1:25:03 AM7/29/15
to Ansible Project, alexand...@kapptivate.com
Reply all
Reply to author
Forward
0 new messages