Re-using a pre_task and post_task using roles?

42 views
Skip to first unread message

Samnang Sen

unread,
Mar 12, 2015, 4:07:37 PM3/12/15
to ansible...@googlegroups.com
Let's say I need to deploy two sets of applications - PHP vs PERL.

I want to be able to re-use the pre_tasks and post_tasks snippet so that i dont have to make changes to multiple scripts if I modify a value for the netscaler module. I guess my question is what's the point of using "pre_tasks" and "post_tasks" if I can put them inside a role as dependencies?

See below for original script. I would essentially do the same thing for my perl deploys. I would like to throw the "pre_tasks" and "post_tasks" into one file and call them when I need to. What's the best way to handle that?

  
- hosts: webservers
  gather_facts: no

  vars_files:
  - "group_vars/deploy_list_sam"

  serial: 3

  vars:
    type: service
    name: "https.svc.{{ inventory_hostname }}.{{ environment_id }}"

  pre_tasks:
  - name: disable service in the lb
    netscaler: nsc_host={{nsc_host}} user={{nsc_user}} password={{nsc_pass}} name={{name}} type={{type}} action=disable validate_certs=no
    delegate_to: 127.0.0.1
    tags: ns_remove_web

  roles:
  - web

  post_tasks:
  - name: enable in the lb
    netscaler: nsc_host={{nsc_host}} user={{nsc_user}} password={{nsc_pass}} name={{name}} type={{type}} action=enable validate_certs=no
    delegate_to: 127.0.0.1
    tags: ns_add_web

Tomasz Kontusz

unread,
Mar 13, 2015, 3:46:24 AM3/13/15
to ansible...@googlegroups.com
You can create additional lb/disable_host and lb/enable_host roles.
You can also try parameterizing the deploy role name and then using playbook-level includes, but I'm not sure if that'll work

Samnang Sen <samna...@gmail.com> napisał:

--
Wysłane za pomocą K-9 Mail.
Reply all
Reply to author
Forward
0 new messages