personal_ansible_desktop_configs icon indicating copy to clipboard operation
personal_ansible_desktop_configs copied to clipboard

Specific roles for a particular machine

Open janvanveldhuizen opened this issue 4 years ago • 3 comments

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

janvanveldhuizen avatar Feb 13 '21 17:02 janvanveldhuizen

Hey Jan,

you could refer to the machines hostname for example:

  • name: install apache webserver   package:     name:  apache2     state: latest   when:     - "'www' in ansible_hostname"

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.

fhmbrg avatar Feb 13 '21 18:02 fhmbrg

@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

janvanveldhuizen avatar Feb 13 '21 18:02 janvanveldhuizen

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

gotmax23 avatar Jul 01 '21 00:07 gotmax23

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!

LearnLinuxTV avatar Oct 13 '22 15:10 LearnLinuxTV