Reduce duplicate/repeated steps in playbook

46 views
Skip to first unread message

Pawan Kumar

unread,
Jul 19, 2020, 2:58:07 PM7/19/20
to Ansible Project





Hi ,Team

Require your help to reduce repeated steps , in the following playbook ,3 roles are common ,but 2 roles(  permission.yml & reload_base_service.yml)  variable value is different

 - hosts: masters
  gather_facts: yes
  vars:
    - owner: "roks"
    - mode: "0644"
    - base_service: "mot-idm"
  tasks:
    - include_role:
        name: motors
        tasks_from: "{{ item }}"
      with_items:
        - permission.yml
        - reload_base_service.yml
        - restart_component.yaml

- hosts: organization
  gather_facts: yes
  vars:
    - owner: "taxi"
    - mode: "0755"
    - base_service: "mzee-org"
  tasks:
    - include_role:
        name: motors
        tasks_from: "{{ item }}"
      with_items:
        - permission.yml
        - reload_base_service.yml
        - restart_component.yaml

- hosts: doxy
  gather_facts: yes
  vars:
    - owner: "matter"
    - mode: "0644"
    - base_service: "rater-x"
  tasks:
    - include_role:
        name: motors
        tasks_from: "{{ item }}"
      with_items:
        - permission.yml
        - reload_base_service.yml
        - restart_component.yaml


Thanks

Pawan Kumar

unread,
Jul 20, 2020, 12:12:27 PM7/20/20
to ansible...@googlegroups.com
Hi Team 

Any thoughts on reducing this repetition !!

Thanks 

--
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 ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/12f8588f-4bdd-487c-9761-024b39d9591eo%40googlegroups.com.

Gajendra Gaikwad

unread,
Jul 20, 2020, 3:21:47 PM7/20/20
to ansible...@googlegroups.com
Yes check if this logic works
1. Create a one group in inventory  with all child group masters, organization and doxy
So that you can run the restart role

2. Set the variables on group level masters, organization and doxy
So that your role will automatically  read this variables while executing 

So it will be only two plays 
Remember running role sequence  is in your hand 

Regards
Gg



Pawan Kumar

unread,
Jul 21, 2020, 10:57:54 AM7/21/20
to ansible...@googlegroups.com
Thanks Gajendra ,will test on the mentioned suggestions &  revert back.


Abhijeet Kasurde

unread,
Jul 21, 2020, 11:17:44 AM7/21/20
to ansible...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages