You could register the result of the file adding in each role, to a variable. At the end you use that to decide if an apt task should be run that updates the cache.
On Mon, 4 Jul 2022 at 05:24, Glen Huang <[email protected]> wrote: > Hi, > > I have a couple of roles that add files to sources.list.d, and then > install packages. Is it somehow possible to run the apt module to update > apt index after ALL roles have added the files but before installing > packages? I have tried a few approaches, none seems ideal: > > 1. Not making roles adding sources.list file, but instead put them in a > central folder and use pre_tasks to add files and run apt before running > roles. > > This means if a role is not included, the corresponding sources.list file > is still added. > > 2. Split each role into two roles, where one is for adding sources.list, > the other installing packages. > > With this approach, I use two loops, each in a separate playbook task, > where the first loop includes roles that add sources.list files, and then > apt module is run, and finally the second loop includes roles that install > packages. > > This forces me to explicitly list all roles needed (including > dependencies) in a variable. > > I wonder if there exist an elegant solution to run apt only once for all > roles? > > Regards, > Glen > > -- > 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/f7819f6c-63ad-4d1f-a5d0-8622ab54a926n%40googlegroups.com > <https://groups.google.com/d/msgid/ansible-project/f7819f6c-63ad-4d1f-a5d0-8622ab54a926n%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- Sent from Gmail Mobile -- 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/CAF8BbLYQ_Yc_6fT58StUWpue3D3VYX4oPupjkQ%3DhQ7Azom%2BTwA%40mail.gmail.com.
