Hi,
these are the ansible role config files

 ansible/runsetup.yml
---
- hosts: 
    - cmp
  become: true
  tags: 
    - nfs_server
  roles:
    - nfs

- hosts:
    - hardware:!cmp
    - vms
  become: true
  tags: 
    - nfs_client
  roles:
    - nfs

ansible/nfs/tasks/main.yml
 ---
# tasks file for installing nfs
- name: configure nfs server
  include_tasks: nfs_server.yml
  tags:
    - nfs_server
- name: configure nfs client
  include_tasks: nfs_client.yml
  tags:
    - nfs_client

/ansible/nfs/tasks/ nfs_server.yml
---
- name: Create shared nfs directory
...
- name: Configure /etc/exports
...
- name: set symlink /media/nfs-share -> /Data/nfs-share
...
- name: set symlink to ansible hosts.ini
...


/ansible/nfs/tasks/ nfs_clientym
---
- name: Create sharing nfs directory on hosts/guests
...
- name: Mounting /media/nfs-share
...


This is the ansible console output - 
all tasks included in nfs_server.yml and nfs_client.yml are exectuted for 
cmp (server) and then it starts again with nfs_server.yml for 
top1...(clients) and stops because set symlink cannot be exectuted on 
clients, which is ok.
in this case tagging in roles doesn't work.


PLAY [cmp] 
***************************************************************************************************************************************************************
TASK [Gathering Facts] 
***************************************************************************************************************************************************
ok: [cmp1]
TASK [configure nfs server] 
**********************************************************************************************************************************************
included: /Data/nfs-share/ansible/nfs/tasks/nfs_server.yml for cmp1
TASK [Create shared nfs directory] 
***************************************************************************************************************************************
ok: [cmp1] => 
TASK [nfs : Configure /etc/exports] 
**************************************************************************************************************************************
ok: [cmp1] => 
TASK [nfs : Commmand exportfs] 
*******************************************************************************************************************************************
skipping: [cmp1] =>
TASK [set symlink /media/nfs-share -> /Data/nfs-share] 
*******************************************************************************************************************
ok: [cmp1] =>
TASK [nfs : set symlink to ansible hosts.ini] 
****************************************************************************************************************************
changed: [cmp1] => 
TASK [configure nfs client] 
**********************************************************************************************************************************************
included: /Data/nfs-share/ansible/nfs/tasks/nfs_client.yml for cmp1
TASK [Create sharing nfs directory on hosts/guests] 
**********************************************************************************************************************
ok: [cmp1] => 
TASK [Mounting /media/nfs-share] 
*****************************************************************************************************************************************
changed: [cmp1] => 

PLAY [hardware:!cmp,vms] 
*************************************************************************************************************************************************
TASK [Gathering Facts] 
***************************************************************************************************************************************************
ok: [top1]
...
TASK [configure nfs server] 
**********************************************************************************************************************************************
included: /Data/nfs-share/ansible/nfs/tasks/nfs_server.yml for top1, 
top2,...
TASK [Create shared nfs directory] 
***************************************************************************************************************************************
changed: [top1]
...
TASK [nfs : Configure /etc/exports] 
**************************************************************************************************************************************
hanged: [top1] => 
...
TASK [nfs : Commmand exportfs] 
*******************************************************************************************************************************************
skipping: [top1]
...
TASK [set symlink /media/nfs-share -> /Data/nfs-share] 
*******************************************************************************************************************
fatal: [top1]:
....
PLAY RECAP 
***************************************************************************************************************************************************************

Thx,
Robert


[email protected] schrieb am Donnerstag, 24. November 2022 um 21:34:46 UTC+1:

> Show us your playbooks, roles, and output, and we can tell you why.
> Without any of those, we'd be guessing just like you.
>
>
> On 11/24/22 3:23 PM, RG wrote:
>
> Hi, 
> i once again exactly followed your instruction by copying your published 
> config into the files, because your methon seems comprehensive to me.
> However the problem is that the tags are not used which means that both 
> tasks are executed completely twice - first for cmp machine and then for 
> the other machines.
> Do you've an idea why this happens.
>
> Thx
>
> [email protected] schrieb am Mittwoch, 23. November 2022 um 14:31:52 
> UTC+1:
>
>> It sounds like you want one NFS role that can do both NFS server and NFS 
>> client tasks. Were I designing such a role I think I would use a variable 
>> or tag to identify which "persona" you want the role to configure, and use 
>> that in the tasks/main.yml to source two different task files. One task 
>> file would do the work for an NFS server persona. One task file would do 
>> the work for an NFS client persona. 
>>
>>
>> roles/nfs/tasks/main.yml
>> ---
>> - name: configure nfs server
>>   include_tasks: nfs_server.yml
>>   tags: nfs_server
>>
>> - name: configure nfs client
>>   include_tasks: nfs_client.yml
>>   tags: nfs_client
>> ...
>>
>> roles/nfs/tasks/nfs_server.yml
>> ---
>> - name: tasks to configure nfs servers
>>   some_tasks:
>> ...
>>
>>
>> roles/nfs/tasks/nfs_client.yml
>> ---
>> - name: tasks to configure nfs clients
>>   some_tasks:
>> ...
>>
>>
>> This lets you separate the tasks for server and client persona. Executing 
>> the role with tag nfs_server will configure the inventory machines as nfs 
>> servers. Executing the role with tag nfs_client will configure the 
>> inventory machines as nfs clients. Execute the role two times with 
>> different inventories and tags as you showed in your original message.
>>
>>
>> my_playbook.yml
>> ---
>> - hosts: cmp
>>   become: true
>>   tags: nfs_server
>>   roles:
>>     - nfs
>>
>> - hosts:
>>     - hardware:!cmp
>>     - vms
>>   become: true
>>   tags: nfs_client
>>   roles:
>>     - nfs
>>
>>
>> I am curious to have others also propose ideas to see how others might 
>> address the problem.
>>
>> Walter
>> --
>> Walter Rowe, Division Chief
>> Infrastructure Services, OISM
>> Mobile: 202.355.4123 <(202)%20355-4123>
>>
>> On Nov 23, 2022, at 8:08 AM, Robert Grießner <[email protected]> 
>> wrote:
>>
>> Hi, 
>> i'd like to migrate my playbooks into a ansible role. I started but a 
>> basic question raises.
>> E.g.
>> I sould like to implement nfs in network of linux machines. on one 
>> machine i've to configure the nfs-sharing and on the other machines I've to 
>> implemt the link to the nfs-sourcing host.
>>
>> systemA - configure a share for other hosts
>> systemB,C,D - use the nfs-sharing from system A
>>
>> I tried to create a role called nfs where i have to configure a few tasks 
>> on systemA and the other tasks on systemB,C,D
>> I've splitted the tasks into 2 vaious task files one for systemA and one 
>> for systemB and both will be imported into main.yml in tasks.
>> ---
>> # tasks file for installing nfs
>> - import_tasks: install_cmp.yml
>> - import_tasks: install_machines.yml
>>
>> in the run.yml I tried to call the same role twice where I used tags to 
>> call the plays for the cmp machine from install_cmp.yml and the tags in 
>> install_machines for running the plays for the other machines. however this 
>> doesn't work
>>
>> - hosts: cmp
>>   become: true
>>   tags:
>>     - create_nfs_cmp
>>     - config_exports_cmp
>>     - exportfs_cmp
>>     - symlink_cmp
>>     - symlink_hostsini_cmp
>>   roles:
>>     - nfs
>>
>> - hosts:
>>     - hardware:!cmp
>>     - vms
>>   become: true
>>   tags:
>>     - create_nfs_machines
>>     - mnt_nfs_machines
>>   roles:
>>     - nfs
>>
>>
>> is my concept wrong, do I have to configure to roles one for setting up 
>> nfs on cmp and one for implementing nfs on the machines or is it possible 
>> to create just one role for installing nfs on with vaious tasks on various 
>> machines?
>>
>> Thx
>>
>>
>

-- 
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/3b50c342-d700-43aa-aabc-b30e073160abn%40googlegroups.com.

Reply via email to