I am new to ansible. I have a small scenario. So I pass the name of the branch using ansible when I run it. In my play book I have:
# Deploy docker container
- include_role:
name: devops/deployment.docker
vars:
docker_name: "docker name is based on the branch id develop dev if UAT test if master then it should be prod"
when: build_type in "develop master UAT"
and in devops/deployment.docker I have a role which deploy a docker image.
- name: push docker container
docker_image:
name: "{{ docker.registery }}/docker_name"
source: build
build:
nocache: true
path: "{{ travis.base_build_path }}"
tag: "{{ ucd.component_version }}"
push: yes
So I send build_type as develop,UAT or master when I run the ansible this role will be called. Now there is an issue:
I need to build my image based on the branch so the code needs to be intelligent and when I send develop it should go search for the key assigned to develop and get the related docker name and build it. something similar to this:
{
develop: {
dockerName:dev
},
master: {
dockerName: prod
},
UAT: {
dockerName: test
}
}
If anyone help me how to do it in ansible I really appreciate it