Here is my entire playbook:
---
- name: "Play 1"
hosts: localhost
gather_facts: no
tasks:
- name: "Search database"
command: > mysql --user=root --password=p@ssword deployment
--host=localhost -Ns -e "SELECT dest_ip,file_dets,install_dir,layer
FROM deploy_dets"
register: command_result
- debug:
msg: "User was {{ item.split('\t')[3] }}"
with_items: "{{ command_result.stdout_lines }}"
- debug:
vars:
USER: "{{ 'user1' if item.split('\t')[3] == 'FrontEnd' else 'user2'
}}"
msg: "User is {{ USER }}"
with_items: "{{ command_result.stdout_lines }}"
On Wednesday, September 25, 2019 at 1:40:38 PM UTC+5:30, Stefan Hornburg
(Racke) wrote:
>
> On 9/25/19 9:58 AM, Mohtashim S wrote:
> > | - debug:
> > msg: "User was {{ item.split('\t')[3] }}"
> > with_items: "{{ command_result.stdout_lines }}"|
> >
> >
> > The above give me the below output:
> >
> > "msg": "User was FrontEnd"
> > "msg": "User was BackEnd"
> >
> >
> > I now wish to set USER variable as user1 is returned value is FrontEnd
> else USER value should be user2.
> >
> > I dont know how to do this but below is my failing playbook.
> >
> > | - debug:
> > vars:
> > USER: "{{ 'user1' if item.split('\t')[3] == 'FrontEnd' else
> 'user2' }}"
> > msg: "User is {{ USER }}"
> >
> > with_items: "{{ command_result.stdout_lines }}"|
> >
> >
> > Expected output is:
> >
> > "msg": "User is user1"
> > "msg": "User is user2"
> >
> >
> >
> > Can you please suggest ?
> >
>
> Hello,
>
> what is the output that you actually get ... and please don't post the
> same question twice.
>
> Regards
> Racke
>
> > --
> > 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:> <mailto:
> [email protected] <javascript:>>.
> > To view this discussion on the web visit
> >
> https://groups.google.com/d/msgid/ansible-project/11286705-639c-43e2-8e0d-47080203cfc1%40googlegroups.com
>
> > <
> https://groups.google.com/d/msgid/ansible-project/11286705-639c-43e2-8e0d-47080203cfc1%40googlegroups.com?utm_medium=email&utm_source=footer>.
>
>
>
>
> --
> Ecommerce and Linux consulting + Perl and web application programming.
> Debian and Sympa administration. Provisioning with Ansible.
>
>
--
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/b669ded5-a252-44b9-b49a-000444a47b48%40googlegroups.com.