I think it makes sense to put both the client and server tasks in the
same role, especially if you have some hosts which are both nfs clients
and nfs servers.
However, I would recommend that you not use the tags keyword at the play
level. It's a short cut way to add a tag or tags to every task involved
in the play. While there must be some problem for which that is a
solution, you don't have such a problem, at least not in my opinion.
A more straightforward approach would be to use /host groups/. Let's say
you have host groups rg_nfs_clients and rg_nfs_servers. Then in your
nfs/tasks/main.yml you have something like
---
# ansible/nfs/tasks/main.yml
- name: Configure NFS Servers
ansible.builtin.include_tasks: nfs_server.yml
when: inventory_hostname in groups['rg_nfs_servers']
tags:
- always
- name: Configure NFS Clients
ansible.builtin.include_tasks: nfs_client.yml
when: inventory_hostname in groups['rg_nfs_clients']
tags:
- always
Then your playbook becomes
---
# my_playbook.yml
- name: Configure NFS
hosts: all # <-- or any subset of "all"
become: true
roles:
- nfs
Whatever hosts you throw at it, it's only going to put nfs server
configs on hosts in your rg_nfs_servers group, and likewise it will only
configure your rg_nfs_clients members as nfs clients. For hosts that are
in neither group, it will do nothing.
The "tags: always" on those ansible.builtin.includes are so that, if you
ever do put tags on the included task files tasks, you can still make
use of those tags from the command line. It ensures the include tasks
happen even when faced with otherwise task-limiting command line tags.
--
Todd
On 11/25/22 10:38 AM, Robert Grießner wrote:
hi, my intention is to migrate various playbooks to absible roles,
setting up a system consisting of various machines. i would like to
start the new ansible role playbook once doing the whole stuff. one
item will be configuring nfs on server and clients. is it a good idea
to use one role for this nfs-task and how could i realize it? until
now i don't or whether it works with tags or any other solution or is
it in general usual and easier in this case to build two roles one for
server and one for client?
--
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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/214401cc-9dd1-4fe5-1f1d-b69cd3a14e5b%40gmail.com.