On 09/05/2022 22:06, Marc Haber wrote:
Hi,

after using ansible for quite a while, my project to manage my own
servers has grown to a respectable size. I was a puppet user before, so
I have a single big playbook containing everything. I have the feeling
this is like holding ansible wrong, and I also have the feeling that I
have my playbook structured wrong. Judging from the single "name"
setting, I took the wrong turn in the very beginning. The playbook does
what it is intended to do, however.

My two cents:

- host name / remote user should be in the inventory and not in the playbook
- consider using import_role instead of include_role

Regards
       Racke


Here is an excerpt from my playbook.

---
- name: apply common configuration
   hosts: all
   remote_user: zgansible
   become: "yes"
   tasks:
   ⦙ - name: install ansible dependencies
   ⦙ ⦙ apt:
   ⦙ ⦙ ⦙ name: ['python3', 'python3-apt']
   ⦙ ⦙ ⦙ state: present
   ⦙ - name: get package facts
   ⦙ ⦙ package_facts:
   ⦙ ⦙ ⦙ manager: "auto"
   ⦙ ⦙ tags: always
   ⦙ - name: print facts
   ⦙ ⦙ debug:
   ⦙ ⦙ ⦙ var: ansible_facts
   ⦙ ⦙ tags: [never, debug, printfacts]
   ⦙ - name: print package facts
   ⦙ ⦙ debug:
   ⦙ ⦙ ⦙ var: ansible_facts.packages
   ⦙ ⦙ tags: [never, debug, printpackagefacts]
   ⦙ - include_role:
   ⦙ ⦙ ⦙ name: clean-motd
   ⦙ ⦙ ⦙ apply:
   ⦙ ⦙ ⦙ ⦙ tags:
   ⦙ ⦙ ⦙ ⦙ ⦙ - clean-motd
   ⦙ ⦙ ⦙ ⦙ ⦙ - clean-all
   ⦙ ⦙ ⦙ ⦙ ⦙ - never
   ⦙ ⦙ tags:
   ⦙ ⦙ ⦙ - clean-motd
   ⦙ ⦙ ⦙ - clean-all
   ⦙ ⦙ ⦙ - never
   ⦙ - include_role:
   ⦙ ⦙ ⦙ name: sysctl
   ⦙ ⦙ ⦙ apply:
   ⦙ ⦙ ⦙ ⦙ tags:
   ⦙ ⦙ ⦙ ⦙ ⦙ - sysctl
   ⦙ ⦙ tags:
   ⦙ ⦙ ⦙ - sysctl
(LOTS of other include_role stanzas defining roles that are on all machines)

- name: apply configuration for bind9 servers
   hosts:
   ⦙ - alemana
   ⦙ - cadencia
   ⦙ - gancho
   ⦙ - impetus
   ⦙ - lasso
   ⦙ - torres
   ⦙ - dns1
   remote_user: zgansible
   become: "yes"
   vars:
   ⦙ bind_role: "{{ (bind|default({}))|combine(bind_group|default({}), 
recursive=true, list_merge='append') }}"
   tasks:
   ⦙ - include_role:
   ⦙ ⦙ ⦙ name: bind9
   ⦙ ⦙ ⦙ apply:
   ⦙ ⦙ ⦙ ⦙ tags:
   ⦙ ⦙ ⦙ ⦙ ⦙ - bind9
   ⦙ ⦙ tags:
   ⦙ ⦙ ⦙ - bind9

- name: apply configuration for DHCP servers
   hosts:
   ⦙ - chasse
   ⦙ - cadencia
   remote_user: zgansible
   become: "yes"
   tasks:
   ⦙ - include_role:
   ⦙ ⦙ ⦙ name: isc-dhcp-server
   ⦙ ⦙ ⦙ apply:
   ⦙ ⦙ ⦙ ⦙ tags:
   ⦙ ⦙ ⦙ ⦙ ⦙ - isc-dhcp-server
   ⦙ ⦙ tags:
   ⦙ ⦙ ⦙ - isc-dhcp-server

Is this the way to do it? Any comments will be appreciated.

In the other news, where would I correctly place (and activate) this handler:

---
- name: apt update
   command: "apt-get update"

if I intend to notify this handler from any role that might use the apt
provider to install packages?

Thank you in advance!

Greetings
Marc



--
Automation expert - Ansible and friends
Linux administrator & Debian maintainer
Perl Dancer & conference hopper

--
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-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/b4b9b565-4a21-74f4-2874-ffaeab056549%40linuxia.de.

Attachment: OpenPGP_signature
Description: OpenPGP digital signature

Reply via email to