Please try this one --- hosts: localhost tasks: - name: "subtask" command: lsblk --nodeps | grep disk | wc -l register: disk_count_result
- name: "set fact" set_fact: disk_count: "{{ disk_count_result.stdout | int }}" - name: "print disk count" debug: msg: "Disk count is {{ disk_count }}" - name: "use disk count in environment variable" shell: echo "Disk Count: {{ disk_count }}" environment: MY_DISK_COUNT: "{{ disk_count }}" On Sun, 15 Oct, 2023, 23:13 Y.G Kumar, <ygkuma...@gmail.com> wrote: > Hi All, > > Please don't yell at me for posting in this group. > I have already written to the ansible project group. > They are saying it is not possible to achieve the following result. > I have written the below code and it is not working. > > ---- > hosts: localhost > tasks: > - name: "subtask" > shell: lsblk --nodeps | grep disk | wc -l > register: disk_count > environment: "{{ disk_count.stdout }}" > -- > > It is throwing undefined variable disk_count. I want to capture the value > of > the shell command output into an environment variable. But it is not > working. > Can someone help me achieve this ? > > Thanks > > -- > You received this message because you are subscribed to the Google Groups > "Ansible Development" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to ansible-devel+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/ansible-devel/235199ad-4ac5-4928-92a1-70512b098cf8n%40googlegroups.com > <https://groups.google.com/d/msgid/ansible-devel/235199ad-4ac5-4928-92a1-70512b098cf8n%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- You received this message because you are subscribed to the Google Groups "Ansible Development" group. To unsubscribe from this group and stop receiving emails from it, send an email to ansible-devel+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-devel/CABAvFDPKpwuvJuYJwszTc5hMahwO3583xQmtGJET3-%3DpRuwXZA%40mail.gmail.com.