How to properly structure ansible options?

I am writing an ansible playbook for installation of consul and nomad. Each of them can be either a client, or a server, or not installed at all.

What is the recommended way to represent which action should be done on which hosts in ansible?

  1. Using groups and roles? This causes high duplication between templates, as the client and server share the same configuration. Additionally, nomad configuration depends on consul, I do not know if I should check a variable in nomad template or if a host is in a group?
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>roles/
nomad_client/tasks/main.yml
nomad_server/tasks/main.yml
nomad_remove/tasks/main.yml
consul_client/tasks/main.yml
consul_server/tasks/main.yml
consul_remove/tasks/main.yml
</code>
<code>roles/ nomad_client/tasks/main.yml nomad_server/tasks/main.yml nomad_remove/tasks/main.yml consul_client/tasks/main.yml consul_server/tasks/main.yml consul_remove/tasks/main.yml </code>
roles/
  nomad_client/tasks/main.yml
  nomad_server/tasks/main.yml
  nomad_remove/tasks/main.yml
  consul_client/tasks/main.yml
  consul_server/tasks/main.yml
  consul_remove/tasks/main.yml
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>all:
nomad_clients:
hosts:
a:
b:
nomad_servers:
hosts:
c:
d:
nomad_remove:
hosts:
e:
f:
/* etc with consul */
</code>
<code>all: nomad_clients: hosts: a: b: nomad_servers: hosts: c: d: nomad_remove: hosts: e: f: /* etc with consul */ </code>
all:
  nomad_clients:
    hosts:
      a:
      b:
  nomad_servers:
    hosts:
      c:
      d:
  nomad_remove:
    hosts:
      e:
      f:
   /* etc with consul */
  1. Using variables with different states?
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>roles/
nomad/
tasks/
main.yml
^- include_tasks: '{{"nomad_remove.yml" if nomad_remove else "nomad.yml" if nomad_server_enable or nomad_client_enable else "error"}}'
nomad.yml
nomad_remove.yml
consul.yml
consul_remove.yml
</code>
<code>roles/ nomad/ tasks/ main.yml ^- include_tasks: '{{"nomad_remove.yml" if nomad_remove else "nomad.yml" if nomad_server_enable or nomad_client_enable else "error"}}' nomad.yml nomad_remove.yml consul.yml consul_remove.yml </code>
roles/
  nomad/
    tasks/ 
       main.yml
         ^- include_tasks: '{{"nomad_remove.yml" if nomad_remove else "nomad.yml" if nomad_server_enable or nomad_client_enable else "error"}}'
       nomad.yml
       nomad_remove.yml
       consul.yml
       consul_remove.yml
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>all:
clients:
hosts:
a:
b:
vars:
nomad_client_enable: 1
nomad_server_enable: 0
nomad_remove: 0
consul_client_enable: 1
consul_server_enable: 0
consul_remove: 0
servers:
hosts:
c:
d:
vars:
nomad_client_enable: 1
nomad_server_enable: 1
nomad_remove: 0
consul_client_enable: 1
consul_server_enable: 1
consul_remove: 0
no_nomad:
hosts:
e:
f:
vars:
nomad_client_enable: 0
nomad_server_enable: 0
nomad_remove: 1
consul_client_enable: 0
consul_server_enable: 0
consul_remove: 1
</code>
<code>all: clients: hosts: a: b: vars: nomad_client_enable: 1 nomad_server_enable: 0 nomad_remove: 0 consul_client_enable: 1 consul_server_enable: 0 consul_remove: 0 servers: hosts: c: d: vars: nomad_client_enable: 1 nomad_server_enable: 1 nomad_remove: 0 consul_client_enable: 1 consul_server_enable: 1 consul_remove: 0 no_nomad: hosts: e: f: vars: nomad_client_enable: 0 nomad_server_enable: 0 nomad_remove: 1 consul_client_enable: 0 consul_server_enable: 0 consul_remove: 1 </code>
all:
  clients:
    hosts:
      a:
      b:
    vars:
      nomad_client_enable: 1
      nomad_server_enable: 0
      nomad_remove: 0
      consul_client_enable: 1
      consul_server_enable: 0
      consul_remove: 0
   servers:
     hosts:
       c:
       d:
     vars:
      nomad_client_enable: 1
      nomad_server_enable: 1
      nomad_remove: 0
      consul_client_enable: 1
      consul_server_enable: 1
      consul_remove: 0
  no_nomad:
    hosts:
      e:
      f:
    vars:
      nomad_client_enable: 0
      nomad_server_enable: 0
      nomad_remove: 1
      consul_client_enable: 0
      consul_server_enable: 0
      consul_remove: 1

Which design is easier to maintain and operate on? Additionally, nomad configuration depends on if consul is enabled or not. In templates when enabling a block of code, should I check a variable in role {% if consul_enable %} or check hostname association {% if inventory_hostname in groups.consul_clients %}? Which one is more commonly used, is there a difference?

Or it is all opinion based and cosmetics?

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật