I have completed an Infrastructure-as-Code project using Terraform and Ansible. Currently, I organize my project as follows:
Project1
Terraform
ec2.tf
rds.tf
…
variables.tf
scripts\<some script files>
templetes\<some tfl files as templates>
Ansible
Playbooks<some playbook yml files>
playbook1.yml
playbook2.yml
……
ansible_hosts
vars\<some variable files used by vars_file>
files\<files to be copied to remote hosts>
templates\<jinja2 templated files>
roles\<some roles such as webserver, dbserver, etc.>
Note I did not layout Ansible code using the following links yet:
- https://leucos.github.io/ansible-files-layout
- http://docs.ansible.com/ansible/latest/playbooks_best_practices.html
e.g. I did not put vars/
, templates/
, files/
to individual role folder since Most of my roles did not have vars and templates. Besides, I want to manage vars
, templates
, files
in one file instead of multiple roles, so I moved vars/
, templates/
and files/
out of roles/
.
For my next project, I may build an Infrastructure-as-code project using CloudFormation/Terraform and Ansible/Chef. Next, I may work on Jenkins, code pipeline, and so on.
In general, should I organize my DevOps projects based on projects, in this way:
Project1:
Terraform
Ansible
Project2:
Terraform
Ansible
......
Or should I organize my DevOps projects based on tools, in this way:
Terraform
Project1
Project2
Ansible
Project1
Project2
Cloudformation
Project3
Project4
I believe separate with projects makes more sense. but then how do we reuse code? for example, what if project1 and project2 use similar terraform code and some ansible roles. and I want to reuse the code of project1 to project2?
or is there any typical samples online I can refer?