Hello,
I am running docker swarm with Ansible, my playbook deploys a docker image
on specific node using swarm, post that deployment I want to execute
certain Ansible tasks on the host where the image is deployed (still
running from the same playbook role), as I am using consul as my backend I
am able to retrieve the host(s) where the image is deployed and used
"add_host" to create a host group.
I don't know how to trigger the tasks via "include" on that hosts. Any
thoughts how to achieve that ?
Below are the references of the main.yml of the role and the include file.
Regards,
Kamesh
*main.yml*
---
- set_fact:
portal_compose_dir: "{{ compose_configs_dir }}/{{app_name}}/portal"
tags: [liferay]
- set_fact:
liferay_home_dir: "{{liferay_base_dir}}/{{app_name}}"
tags: [liferay]
- include: rollback.yml
when: rollback_app is defined
- name: "Create Liferay Directories"
file:
dest: "{{ item }}"
state: directory
with_items:
- "{{ portal_compose_dir }}"
tags: [liferay]
- name: "Liferay App Swarm Filters"
template:
src: constraints.env.j2
dest: "{{ portal_compose_dir }}/constraints.env"
tags: [liferay]
- name: "Liferay Docker Compose"
template:
src: "liferay-compose.yml.j2"
dest: "{{ portal_compose_dir }}/docker-compose.yml"
tags: [liferay]
## TODO Refresh versions
- name: "Pull the Liferay App"
shell: docker-compose pull lportal
args:
chdir: "{{ portal_compose_dir}}"
environment:
DOCKER_HOST: "tcp://{{ ip }}:2376"
DOCKER_CERT_PATH: "/home/{{ ansible_ssh_user }}/.docker"
DOCKER_TLS_VERIFY: 1
PATH: "{{ path }}"
tags: [liferay]
- name: "Spin up Liferay Container"
shell: docker-compose up -d --no-recreate lportal
args:
chdir: "{{ portal_compose_dir }}"
environment:
DOCKER_HOST: "tcp://{{ ip }}:2376"
DOCKER_CERT_PATH: "/home/{{ ansible_ssh_user }}/.docker"
DOCKER_TLS_VERIFY: 1
PATH: "{{ path }}"
tags: [liferay]
- name: "Liferay Service Info"
get_url:
url: "http://10.100.199.200/v1/catalog/service/lportal_{{app_name}} "
dest: /tmp/liferay_service_info.json
tags: [liferay-config]
- shell: "cat /tmp/liferay_service_info.json | jq --raw-output '.[] |
.Address ' "
environment:
PATH: "{{ path }}"
register: liferay_hosts_info
tags: [liferay-config]
- debug: var=liferay_hosts_info.stdout
ignore_errors: true
tags: [liferay-config]
- add_host:
groups: liferay_deployed_hosts
name: "{{ liferay_hosts_info.stdout }}"
tags: [liferay-config]
- include: deploy-portal-ext.yml
tags: [liferay-config]
*deploy-portal-ext.yml*
---
- hosts: liferay_deployed_hosts
remote_user: vagrant
sudo: yes
tasks:
handlers:
- name: "Create Liferay Directories"
file:
dest: "{{ item }}"
state: directory
with_items:
- "{{ liferay_home_dir }}"
- "{{ liferay_home_dir }}/www/html"
tags: [liferay-config]
- name: "Liferay Portal Configuration"
template:
src: portal-setup-wizard.properties.ctmpl.j2
dest: "{{ portal_compose_dir }}/portal-setup-wizard.properties.ctmpl"
tags: [liferay-config]
- name: "Deploy Portal Ext Properties"
shell: >
consul-template \
-consul "{{ip}}:8500" \
-template
"{{portal_compose_dir}}/portal-setup-wizard.properties.ctmpl:{{
liferay_home_dir}}/portal-setup-wizard.properties" \
-once
notify: restart liferay
environment:
PATH: "{{ path }}"
tags: [liferay-config]
--
You received this message because you are subscribed to the Google Groups
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/3538bb6e-bf58-4b37-baa8-d26f39e3438d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.