Hello all,
as first requeest into this ml i need to thank Michel to writing
ansible and all other people that help this project with articles,
docs, code, patches, tests, ..
In my test i need to do some operation on machine before and after the
single ansible request start.
The tipical use case is:
* Disconnect machine from load balancer
* Execute maintenance tasks
* Connect machine to load balancer
I start to see the local_action to use local machine tools (eg. clb¹,
not available on nodes) to connect/disconnect the current machine from
LB, but I need more control on stop next macihine execution on error,
or do not disconnect more then one machine at time, ...
I'm just start to planning the work, so if someone have suggestion or
similar request and have resolved, or can me put on the right way..
Thank you!
Marco
¹ clb: https://github.com/calebgroom/clb
Marco,
In my test i need to do some operation on machine before and after the
single ansible request start.
Maybe a simple shell script?
# do stuff before
...
# run Ansible
ansible-playbook .....
# do stuff after?
...
That's how I do it. Simple but effective.
-JP
Marco,
Hello Jan-Piet,
thank for reply.
In my test i need to do some operation on machine before and after the
single ansible request start.
Maybe a simple shell script?
# do stuff before
...
# run Ansible
ansible-playbook .....
# do stuff after?
...
That's how I do it. Simple but effective.
Let me expand my example.
I have hosts:
frontend:
192.168.0.1
192.168.0.2
192.168.0.3
192.168.0.4
192.168.0.5
database:
192.168.1.1
192.168.1.2
I need to execute:
ansible frontend -m application
this require to update my application on server, restart webserver and
make some other operation on each node.
This operation can be "problematic" and require long time (some mins),
so i need to:
* detach machine 192.168.0.1 from LB
* execute ansible task on machine 192.168.0.1
* attach machine 192.168.0.1 to LB
* detach machine 192.168.0.2 from LB
* execute ansible task on machine 192.168.0.2
* attach machine 192.168.0.2 to LB
* ....
to make ansible executing on a single machine I can use --forks 1 to
make sure a single machine will be detach from LB and run ansible
operation on it, but i need to execute detac / attach operation.
I can also use -of course- bash script but I think is not the best way
to use ansible.. or not?
Bye
Marco
Marco Vito Moscaritolo wrote:
Marco,
Hello Jan-Piet,
thank for reply.
In my test i need to do some operation on machine before and after the
single ansible request start.
Maybe a simple shell script?
# do stuff before
...
# run Ansible
ansible-playbook .....
# do stuff after?
...
That's how I do it. Simple but effective.
Let me expand my example.
I have hosts:
frontend:
192.168.0.1
192.168.0.2
192.168.0.3
192.168.0.4
192.168.0.5
database:
192.168.1.1
192.168.1.2
I need to execute:
ansible frontend -m application
this require to update my application on server, restart webserver and
make some other operation on each node.
This operation can be "problematic" and require long time (some mins),
so i need to:
* detach machine 192.168.0.1 from LB
* execute ansible task on machine 192.168.0.1
* attach machine 192.168.0.1 to LB
* detach machine 192.168.0.2 from LB
* execute ansible task on machine 192.168.0.2
* attach machine 192.168.0.2 to LB
* ....
to make ansible executing on a single machine I can use --forks 1 to
make sure a single machine will be detach from LB and run ansible
operation on it, but i need to execute detac / attach operation.
I can also use -of course- bash script but I think is not the best way
to use ansible.. or not?
It sounds like a playbook with something like:
- hosts: frontend
serial: 1
tasks:
- name: detach from load balancer
local_action: ...
- name: deploy application
action: ...
- name: attach to load balancer
local_action: ...
is what you want. serial: 1 will run the entire play on 1 host before
continuing with the next one, ensuring only one of your nodes is out of
the load balancer at any given time, and using local_action to handle the
load balancer.
It sounds like a playbook with something like:
- hosts: frontend
serial: 1
tasks:
- name: detach from load balancer
local_action: ...
- name: deploy application
action: ...
- name: attach to load balancer
local_action: ...
is what you want. serial: 1 will run the entire play on 1 host before
continuing with the next one, ensuring only one of your nodes is out of
the load balancer at any given time, and using local_action to handle the
load balancer.
--
Daniel Hokka Zakrisson
Daniel nailed it exactly.