LearnLinuxTV / personal_ansible_desktop_configs

317 stars 98 forks source link

Specific roles for a particular machine #4

Closed velduz closed 2 years ago

velduz commented 3 years ago

Hi Jay,

I really like this approach, and I am playing around with it to set up the configuration playbooks for my machines. There is one thing that I am wondering, though. In your approach you have two type of machines, the servers and the workstations. But what if you want to set up a particular machine with some specific tasks? I am trying to create a repository which I can use to recreate all machines in my network, including the ones that I have for specific tasks. For example, I have a VM that runs PiHole, and I have another VM as a plex media server. Following your example, these would both be server machines, and will keep their basic server configuration up to date. But they also have tasks that are very specific for their particular function. I was thinking of copying local.yml to pihole.yml and add the pihole playbook to it. Then I have to change the cron job for all machines to pull a $(hostname).yml instead of the default local.yml file.

{ 
  ansible-pull -U -o <myrepo> $(hostname).yml 
} || { 
  ansible-pull -U -o <myrepo> 
}

If a hostname.yml exists, then that playbook will be run instead of the default local.yml.

Does this make sense? Or am I overlooking an easier approach?

Thanks for your examples and instructive videos, anyway!!

Jan

fhmbrg commented 3 years ago

Hey Jan,

you could refer to the machines hostname for example:

So the play is only executed on hosts which have www in their hostname.

Regards, Frank

On 13.02.21 18:13, Jan van Veldhuizen wrote:

Hi Jay,

I really like this approach, and I am playing around with it to set up the configuration playbooks for my machines. There is one thing that I am wondering, though. In your approach you have two type of machines, the servers and the workstations. But what if you want to set up a particular machine with some specific tasks? I am trying to create a repository which I can use to recreate all machines in my network, including the ones that I have for specific tasks. For example, I have a VM that runs PiHole, and I have another VM as a plex media server. Following your example, these would both be server machines, and will keep their basic server configuration up to date. But they also have tasks that are very specific for their particular function. I was thinking of copying local.yml to pihole.yml and add the pihole playbook to it. Then I have to change the cron job for this machine to pull the pihole.yml instead of the default local.yml file.

|{ ansible-pull -U -o $(hostname).yml } || { ansible-pull -U -o } |

If a hostname.yml exists, then that playbook will be run instead of the default local.yml.

Does this make sense? Or am I overlooking an easier approach?

Thanks for your examples and instructive videos, anyway!!

Jan

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/LearnLinuxTV/personal_ansible_desktop_configs/issues/4, or unsubscribe https://github.com/notifications/unsubscribe-auth/AGJ5TT2FLQ6RBE4JEVRD2UTS62XMJANCNFSM4XSKJGIQ.

velduz commented 3 years ago

@ank0m , that makes sense.

Also, looking at local.yml, I can follow the same structure:

- hosts: server
  tags: server
  become: true
  roles:
    - server

- hosts: piholes
  become: true
  roles:
    - pihole
gotmax23 commented 3 years ago

It's also possible to add the same host to multiple groups.

LearnLinuxTV commented 2 years ago

Sorry I missed this comment. The code as I have it already lets you do a per-machine config. That's what the host_vars file does, and that should give you everything needed for that. If you still haven't figured this out though, let me know!