Hey, it worked :) Thanks, Kai and Karl.
On Thursday, 14 March 2019 03:52:09 UTC+5:30, Karl Auer wrote: > > As Kai Stian Olstad wrote, I got the target list wrong. The first > ocurrence of "loglist" should be "logdict", OR (even better) do as Kai > suggested and substitute "logfile_config" for loglist and logdict. > > Regards, K. > > > On Wed, Mar 13, 2019 at 10:08 PM Ashok <[email protected] <javascript:>> > wrote: > >> The content of the source is very dynamic on each run, hence, going >> static isn't viable. >> >> I tried with your logic, like below: >> >> - name: Form list of dicts >> set_fact: >> logfile_config: "{{ logf_dest |default([]) + >> [ { >> 'logfile_name': 'remote.conf', >> 'logfile_pattern': item, >> 'logfile_owner': 'root' >> } >> ] }}" >> with_items: "{{ logf_dest }}" >> >> >> - debug: >> var: logfile_config >> >> It doesn't give the desired output. `logfile_config` is: >> >> TASK [debug] >> ********************************************************************************************************************************* >> task path: /home/ansible/playbooks/loghost-new.yml:42 >> ok: [log-dvl.vpn] => { >> "logfile_config": [ >> "/logs/mx/mail.log", >> "/logs/dyn.log", >> "/logs/apache-servers/other.log", >> { >> "logfile_name": "remote.conf", >> "logfile_owner": "root", >> "logfile_pattern": "/logs/apache-servers/other.log" >> } >> ] >> } >> >> Anything I missed? >> >> >> On Wednesday, 13 March 2019 12:50:31 UTC+5:30, Karl Auer wrote: >>> >>> How dynamic is the content of that source list? One simple approach >>> would be: >>> >>> - logfile_name: remote.conf >>> logfile_pattern: "{{ logf_dest[0] }}" >>> logfile_owner: root >>> - logfile_name: remote.conf >>> logfile_pattern: "{{ logf_dest[1] }}" >>> logfile_owner: root >>> - logfile_name: remote.conf >>> logfile_pattern: "{{ logf_dest[2] }}" >>> logfile_owner: root >>> >>> If the list is not always three items long, you can do it with a loop: >>> >>> - set_fact: >>> logdict: "{{ loglist |default([]) + >>> [ { >>> 'logfile_name': 'remote.conf', >>> 'logfile_pattern': item, >>> 'logfile_owner': 'root' >>> } >>> ] }}" >>> with_items: "{{ logf_dest }}" >>> >>> Anyway, something like that. That's off the top of my head, so you may >>> need to correct the syntax a bit, but you get the idea. >>> >>> Regards, k. >>> >>> >>> On Wed, Mar 13, 2019 at 5:55 PM Ashok <[email protected]> wrote: >>> >>>> Hi All, >>>> >>>> I have a list ` logf_dest ` (of log files): >>>> >>>> "logf_dest": [ >>>> "/logs/mx/mail.log", >>>> "/logs/dyn.log", >>>> "/logs/apache-servers/other.log" >>>> ] >>>> >>>> I need to form a "list of dicts" called ` logfile_config `, like the >>>> below: >>>> >>>> - logfile_name: remote.conf >>>> logfile_pattern: /logs/mx/mail.log >>>> logfile_owner: root >>>> >>>> >>>> - logfile_name: remote.conf >>>> logfile_pattern: /logs/dyn.log >>>> logfile_owner: root >>>> >>>> >>>> - logfile_name: remote.conf >>>> logfile_pattern: /logs/apache-servers/other.log >>>> logfile_owner: root >>>> >>>> >>>> I've come this far in doing so: >>>> >>>> - name: Create list of dicts >>>> set_fact: >>>> logfile_config: | >>>> { >>>> {% for k in logf_dest %} >>>> logfile_name: remote.conf >>>> logfile_pattern: {{ k }} >>>> logfile_owner: root >>>> {% endfor %} >>>> } >>>> >>>> But, above is obviously not formatted correctly. >>>> >>>> I need help on what I am missing here. >>>> >>>> Thanks in advance. >>>> >>>> -- >>>> 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 post to this group, send email to [email protected]. >>>> To view this discussion on the web visit >>>> https://groups.google.com/d/msgid/ansible-project/61b38102-c346-495f-96e5-cd149800d4f9%40googlegroups.com >>>> >>>> <https://groups.google.com/d/msgid/ansible-project/61b38102-c346-495f-96e5-cd149800d4f9%40googlegroups.com?utm_medium=email&utm_source=footer> >>>> . >>>> For more options, visit https://groups.google.com/d/optout. >>>> >>> >>> >>> -- >>> Karl Auer >>> >>> Email : [email protected] >>> Website: http://2pisoftware.com >>> >>> GPG/PGP : 958A 2647 6C44 D376 3D63 86A5 FFB2 20BC 0257 5816 >>> Previous: F0AB 6C70 A49D 1927 6E05 81E7 AD95 268F 2AB6 40EA >>> >> -- >> 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] <javascript:>. >> To post to this group, send email to [email protected] >> <javascript:>. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/ansible-project/20098621-047b-4596-b46c-8c14b37df008%40googlegroups.com >> >> <https://groups.google.com/d/msgid/ansible-project/20098621-047b-4596-b46c-8c14b37df008%40googlegroups.com?utm_medium=email&utm_source=footer> >> . >> For more options, visit https://groups.google.com/d/optout. >> > > > -- > Karl Auer > > Email : [email protected] <javascript:> > Website: http://2pisoftware.com > > GPG/PGP : 958A 2647 6C44 D376 3D63 86A5 FFB2 20BC 0257 5816 > Previous: F0AB 6C70 A49D 1927 6E05 81E7 AD95 268F 2AB6 40EA > -- 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 post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/05e5f026-da13-4764-b2af-245e04bb3bb0%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
