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 <tel:(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/94d6c8a9-1d8f-a557-26ad-e0f4ed730a69%40gmail.com.

Reply via email to