Hi Walter, Yes, that's how I usually go with (no grep + awk). But back then, I was having so many "trouble" escaping the special characters associated with awk's syntax that I decided to go that way. Now that things are looking better, I'll give that a try again. Otherwise I'll miss learning...
Thanks, Alex On Thu, Mar 7, 2024 at 11:28 AM 'Rowe, Walter P. (Fed)' via Ansible Project <ansible-project@googlegroups.com> wrote: > - name: Collect server location > ansible.builtin.shell: "/bin/awk '$1 ~ /{{ inventory_hostname }}/ { > print $3 }' {{ server_list_file }}" > register: grep_result > changed_when: ( grep_result.rc != 0 ) > > You don't need grep AND awk. Learn to use awk's expressions to find what > you need in a single command. > > % cat serverlist.txt > > serverA flavor locationX owner > > serverB flavor locationY owner > > serverC flavor locationZ owner > > > % awk '$1 ~ /serverB/ { print $3; }' serverlist.txt > > locationY > > > Walter > -- > Walter Rowe, Division Chief > Infrastructure Services Division > Mobile: 202.355.4123 > > -- > 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 ansible-project+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/ansible-project/AF495547-15F6-4E50-ACD2-D2B1F1A75945%40nist.gov > <https://groups.google.com/d/msgid/ansible-project/AF495547-15F6-4E50-ACD2-D2B1F1A75945%40nist.gov?utm_medium=email&utm_source=footer> > . > -- [image: Edmonton_sig_RGB_S.jpg] Alex Wanderley Application and Infrastructure Analyst II Server Solutions & Automation Financial and Corporate Services | Open City and Technology 780-496-4156 Office 780-819-0273 Mobile City of Edmonton Century Place, 19th Floor 9803 102A Avenue NW Edmonton AB, T5J 3A3 All information contained in this email post is proprietary to the City of Edmonton, confidential and intended only for the addressed recipient. If you have received this post in error, please disregard the contents, inform the sender of the misdirection, and remove it from your system. The copying, dissemination or distribution of this email, if misdirected, is strictly prohibited. -- *The contents of this message and any attachment(s) are confidential, proprietary to the City of Edmonton, and are intended only for the addressed recipient. If you have received this in error, please disregard the contents, inform the sender of the misdirection, and remove it from your system. The copying, dissemination, or distribution of this message, if misdirected, is strictly prohibited.* -- 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 ansible-project+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CADp8UUQL7PE81p67dSx3DVS1dFgrbqC7mWfmqj-UFwGp%2B0%2B2Lg%40mail.gmail.com.