On 12/05/2022 12:57, Marc Haber wrote:
Hi Dirk,

On Tue, May 10, 2022 at 08:30:13AM +0200, Dick Visser wrote:
On 2022-05-09 (Mon) 22:06, Marc Haber wrote:
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.

Here is an excerpt from my playbook.

---
- name: apply common configuration
   hosts: all
   remote_user: zgansible
   become: "yes"

What is the reason for quoting this boolean? It is usually done to force it
to be a string, but AFAIK this parameter requires a boolean.

Historical reasons, fixed. I probably didnt know any better, and it's
still a matter of try-and-err whether to find out whether ansible
wants/insists on things being quoted or not.

[snip]

I don't see anything totally wrong with the above approach.
Perhaps try to avoid the inline lists but that's cosmetics.

How would I write them any better?

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?

What is the use case for this?
If you want to make sure this is always run prior to any package task, then
you should use the update_cache parameters of the apt module:

https://docs.ansible.com/ansible/latest/collections/ansible/builtin/apt_module.html#parameter-update_cache

updating the package lists after fiddling with things in /etc/apt, for
example preparing a release upgrade or adding an external repository
(docker *cough*). Doing an apt update right before any check whether any
required package is already installed seems overkill, but I need to
ponder about that.

You can add/modify/delete the external repo with Ansible and run the apt update 
only when the repo changed.

The equivalent for "apt-get update" is:

    - name: Update APT cache
      apt:
        update_cache: yes

Regards
       Racke


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/1a200e5e-9c3c-3ab5-84c5-deb494f6f073%40linuxia.de.

Attachment: OpenPGP_signature
Description: OpenPGP digital signature

Reply via email to