Ansible Code
This is the part where the real work will have to be done, it is totally up to you.
Use your knowledge, AI or whatever you want/must to create the automation you need.
I gave you a lot of info, but I cannot automate standards for each and every organization.
There are lots of examples out there, some good, some very outdated, but still examples that can help you create.
You will learn best by doing and failing, not by copiing..
So build, test, fail, rebuild, test again.... itterate until it works..
Testing is the big word here, test until you drop...
Then you will have learnt something, trust and believe in yourself.
Not all of the internet...
Some tips on development:
Create roles:
- Each role has a separate repository
- Keep playbooks small
- Create playbooks to do one thing right
- Related tasks/variables must reside in the same repository
When you migrate from roles to collections, the step is not so big, you move the code from the role, into the roles directory of the collection. This is almost all there is, but version management is no longer on the role itself, but now on collection versions.
So start small, create separate roles..
Example
Create a play to execute the roles based on conditions in inventory (like group membership).
I'll give an example of the play and the roles included for a infrastructure playbook that can handle multiple virtualization platforms. This will not be a functional play, but an example of how you could set things up.
This example is a simplification of actual code used for deployment.
The infrastructure playbook here is called from the automation platform to create a VM on a virtualization platform. The only real parameter the play receives is the hostname of the machine to create. This host is in the inventory where all variables for this host can be found to instanciate the machine.
Very simplified inventory example:
all:
children:
vmware:
children:
ansible:
children:
vm:
hosts:
host-1.example.org:
vmware_cluster:
children:
vmware_nodes:
proxmox:
children:
ansible:
children:
qemu:
hosts:
host-2.example.org:
proxmox_cluster:
children:
proxmox_nodes:
You see here that host-1.example.org is to be deployed on vmware and host-2.example.org is to be deployed on proxmox.
Both virtualization platforms require specific code to be able to create a VM, but how can we call the right roles for each host?
In reality, this inventory is much more complex and part of a dynamic inventory, in which the hosts imported from the platforms are mapped to the groups in the above file.
Simplified infrastructure playbook, called by automation platform in VM creation:
---
- name: Configure the host on infrastructure
hosts: "{{ instances | default('localhost') }}"
gather_facts: false
pre_tasks:
# Run the infrastructure roles to create the VM's and register them to Satellite
roles:
- role: role_infrastructure_vmware
when: "'vmware' in group_names"
- role: role_infrastructure_proxmox_qemu
when: "'qemu' in group_names"
- role: role_infrastructure_lvm
when: lvm is defined
- role: role_infrastructure_satellite
when: satellite_server is defined
If your read the pages leading to this one, you'll see that this play only creates the foundation part of a complete workflow to create a VM including the application, this is the first step that is equal for all virtual machines.
Each step is conditional and depending on variables or group membership, especially the choice of the virtualization platform is dependent of the group membership in the inventory. This makes it easy to migrate a machine between platforms (migrate is not the correct term, relocate by installation is better).
This setup gives a dynamic, inventory driven way to instanciate machines on different platforms, while keeping the base structure the same. Just add sections to the inventory and roles to the infrastructure playbook to enable a new virtualization platform, this way you'll create a modular and extensible deployment strategy, based on inventory variables and groups.
This is just the first layer, but I hope You get the idea.
The first layers will inherit this structure, to make the system compliant for your organization as a base system deployment.
Layers later in the workflow can be specific for the installation (middleware or application).
All layers are stacked in a workflow job_template that executes all layers in the correct order for deployment. (See configuration as code for rhaap for workflow definition).