Yeah, I've turned a full circle... Sorry, but I don't have a better solution...
Piotr wt., 4 gru 2018 o 19:07 John Harmon <[email protected]> napisał(a): > > > On Tuesday, December 4, 2018 at 11:04:15 AM UTC-7, Piotr Owcarz wrote: >> >> John, >> I just realized, that lookups read files on the Ansible control machine. >> I assume you are searching that file on remote machine - then lookup won't >> work. If this is the case, read on... >> I was researchnig a similar issue today, and couldn't came up with other >> solution than: >> - shell: "grep -Eo '\\w+.img' {{ file }}" >> register: out >> - debug: var=out.stdout_lines >> >> Piotr >> >> >> >> >> wt., 4 gru 2018 o 18:21 John Harmon <[email protected]> napisał(a): >> >>> Perhaps I am doing this wrong, but it doesn't like my syntax. If I >>> escape the backslash ('\\w+.img') it tries to run but with a different >>> error: >>> - name: Find virtual Disks >>> set_fact: >>> virt_disks: "{{ lookup('file','/var/ftp/vm.cfg') | >>> regex_findall('\w+.img') }}" >>> >>> Result: >>> ERROR! Syntax Error while loading YAML. >>> found unknown escape character >>> >>> The error appears to have been in >>> '/etc/ansible/playbooks/one-offs/sanitize_vm.yml': line 21, column 75, >>> but may >>> be elsewhere in the file depending on the exact syntax problem. >>> >>> The offending line appears to be: >>> >>> set_fact: >>> virt_disks: "{{ lookup('file','/var/ftp/vm.cfg') | >>> regex_findall('\w+.img') }}" >>> >>> ^ here >>> We could be wrong, but this one looks like it might be an issue with >>> missing quotes. Always quote template expression brackets when they >>> start a value. For instance: >>> >>> with_items: >>> - {{ foo }} >>> >>> Should be written as: >>> >>> with_items: >>> - "{{ foo }}" >>> >>> >>> If I escape the backslash: >>> TASK [Find virtual Disks] >>> **************************************************************************************************************************************************************************************************************** >>> [WARNING]: Unable to find '/var/ftp/vm.cfg' in expected paths (use -vvvvv >>> to see paths) >>> >>> fatal: [ovmftp]: FAILED! => {"msg": "An unhandled exception occurred >>> while running the lookup plugin 'file'. Error was a <class >>> 'ansible.errors.AnsibleError'>, original message: could not locate file in >>> lookup: /var/ftp/vm.cfg"} >>> >>> >>> >>> I find the error strange on the last one, because I stat the file >>> previous to it and can see it fine. >>> >>> -- >>> 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/723d9abf-e640-4494-82c3-565fcdcfeda4%40googlegroups.com >>> <https://groups.google.com/d/msgid/ansible-project/723d9abf-e640-4494-82c3-565fcdcfeda4%40googlegroups.com?utm_medium=email&utm_source=footer> >>> . >>> For more options, visit https://groups.google.com/d/optout. >>> >> > Thx Piotr. That works. I was hoping to be able to do this without shell, > but I haven't been able to find another way around it either. > > -- > 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/0894095e-005e-4e67-8007-56a8b2d9a73e%40googlegroups.com > <https://groups.google.com/d/msgid/ansible-project/0894095e-005e-4e67-8007-56a8b2d9a73e%40googlegroups.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- 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/CACHJvyP839KJ-E0DQ04PgVQ0drdqfrw%3DY-G%3DHXPa_qp%3DLwyO%2Bg%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
