Hi Dick Visser,
Thanks for your reply.
As per your suggestion I am trying to running the shell module first and
registering the output, now what should I do and how I used this register
values in replace module to get the required output.
- shell: 'awk "/^[[:space:]]*($|#)/{next} /$host_to_find/{print \$1 \"
\" }"'
register: extracted_data
For reference I am attaching the file which I am using for this playbook.
xx.yy.zz.aa ssh-rsaAAAAB3NzaC1yc2EAAAABIwAAAQEA6TCzDMKmc/xnTB7Eb
/7xB1ClCYSSA3CbbxaZd31KHV2dI5YdhFzhyMvpilVn5/lBEWk2fOTdRCoieEgmo7gpZl8rQGiqbw7+ePIUGO7JUD5nU+mkRDZTTjupPk/qdjz7gNTSLWDvcbby9QLB3SHHE5iWBgAK1y6yErDgGSsaGV1r7d7XP/Ni0koMJvtZ8ZjC1SP8Ao+rfa+62jjgHmlDxuMqny1OhtT2y12hHQOJC9Vk27IAPdlilouvw7h1sIF2Lt5xr5XQvIJqDcdJXUM+T1a1sessCRq2SQiu7WZc6ID9GPLy2pso552vX7ATSPuSwFtPU/6dZPmgfggFoD7IIw==
xx.yy.zz.aa ssh-rsaAAAAB3NzaC1yc2EAAAADAQABAAABAQDcUrYa1
Gjyf6PNGYLiorFNFsUiEj6NakUkfzMUEX2UJgA+ltt4mdbbnkryrrRulxQDQysAeZQRiuvobp7HNI9bNtdXZU8VsNTXp9etpxmbfVPXMD8FCEOnZSxb1BjoQ7w6w+/pqtGw3i1MUlMIreJWYW87J2CpbiyYufhh74HljLSjfMy1SZcUIFYKV2iJDB3H9GeWhdTT2vkmF9Tx9PMpt4miwKOwVnFs5rrki1nNQbvyesfd3yzTMa3gE0iuIVw3NWHiNN8x65QtfeVlKiXKnGjJO0FUXdilSogz5Aghqswfst7begxyDmvPiz9ALKhp90OBZTI1UwDAMzLTemF5
xx.yy.zz.aa ssh-rsaAAAAB3NzaC1yc2EAAAADAQABAAABAQCrs1Nk7xV2rJ
k02oCSdV3UnT3eKSliJ06BbxeigLIIUC8P5cKQsxEUwG/DP4G06uzr6xIW31LSUDy/lPMZZtPJ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AAQEArDX6pLkuAl
UBStUsp6JYo/6saGg5mm7wQcMegeLhFSP44QDu72srf7vEej0eG1HgCrFKE0mWYyoiYz7ajjslAtvv5GngKrpzkynArriiyxkfeqM8j/G3ZHFn9ZT43k0zxrxq6Po9BvDfwJQwSt2TBq1GPu+jgfNp0s11Uqw7LYSybTxZtmvAOjvzs6juXpn/GFRgUm2ND9qc2sd/Eo4v2WkJiG9fMApxs7iluZ5M91T+8OtSQNEnTzqlnFMcEWAwWhBxy7oOiROeWFmdF6MnbXL2R0hLhdppNXseqA0f+yteVoLlF39X3P2ztDb2VEeyPmgfaFyO7qRb/NH1db3+iQ==
It is a known host file which I am using for my playbook.
Now, how do I pass this register value in replace module or how do I
replace the value in file with the new value.
Looking forward for your reply.
Regards
Sumit Sahay
On Tuesday, 2 October 2018 03:20:17 UTC+5:30, Dick Visser wrote:
>
> On Mon, 1 Oct 2018 at 18:25, SUMIT SAHAY <[email protected]
> <javascript:>> wrote:
> >
> > Hi Dick Visser,
> > Thanks for your reply.
> > Yeah I want to replace the output of awk with string.
> > The playbook is running fine it means it is getting executed without any
> error, that is what I was trying to say.
> >
> > Actually the string may vary as per the requirement as of now I used my
> name to raise my question on Ansible forum.
>
> Hi Sumit
>
> For clarity sake, the 'replace' module "will replace all instances of
> a pattern within a file" (as per
> https://docs.ansible.com/ansible/latest/modules/replace_module.html).
> There is no error because there is nothing to replace.
> However, if you mention "running awk first", then you should, well,
> run awk first. But I don't see that anywhere.
> If you intend to do that, you should use either the 'shell' or the
> 'command' module first.
> Possibly just use a regular expression filter in that same task (and
> avoid having two tasks that each need a file to work on).
>
> https://docs.ansible.com/ansible/latest/user_guide/playbooks_filters.html#regular-expression-filters
>
>
> Things would be a lot easier if you were able to provide a real data
> sample, and a clear description of what you're exactly trying to
> achieve.
>
>
> Thanks
>
> Dick
>
--
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/ea232e76-b69e-4f02-bd0f-b911cfcb6efc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.