Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

    ansible-playbook -i inventory/production playbook/site.yml

For test environment:

    ansible-playbook -i inventory/test playbook/site.yml

repository organization

Inventory/                # here we store our inventory file

   production             # inventory file for production servers

   staging                staging                 # inventory file for staging environment

   test                # inventory file for test environment


 

group_vars/

production/

   generic                # here we assign variables to generic groups

   comanage               # here we assign variables to comanage groups

   teip                   # here we assign variables to TEIP groups

   loadbalancer           # here we assign variables to loadbalance groups

   vault                  # Vault file, to store password and secret informations   

staging/

...

test/

...

 

host_vars/

   hostname1              # if systems need specific variables, put them here

   hostname2              # ""

  

playbook/

   site.yml                  # master playbook

   webservers.yml            # playbook for webserver tier

   dbservers.yml             # playbook for dbserver tier

 

roles/

    generic/               # this hierarchy represents a "role"

        tasks/            #

            main.yml      #  <-- tasks file can include smaller files if warranted

        handlers/         #

            main.yml      #  <-- handlers file

        templates/        #  <-- files for use with the template resource

            ntp.conf.j2   #  <------- templates end in .j2

        files/            #

            bar.txt       #  <-- files for use with the copy resource

            foo.sh        #  <-- script files for use with the script resource

        vars/             #

            main.yml      #  <-- variables associated with this role

        defaults/         #

            main.yml      #  <-- default lower priority variables for this role

        meta/             #

            main.yml      #  <-- role dependencies

 

repository organization

To separate environment vars, we can use a variable inside inventory file to switch in each repository:

Inventory/staging

TEIP

192.168.1.[2:3]

...

...

...

[all:vars]

environment=staging

playbook

- name: a generic playbook

vars_files:

- ../group_vars/{{environment}}/generic.yml

become: yes

remote_user: root

roles:

- roles/generic

 

Ansible take "environment" variable directly from inventory file. For each environment, there is a "environment" varible with its value ("production", "staging" or "test")

 

work in progress..