So, you mean to say that we can't achieve this in ansible ?

On Sunday, October 15, 2023 at 4:21:42 PM UTC+5:30 Dick Visser wrote:

> On Sun, 15 Oct 2023 at 08:24, Y.G Kumar <ygku...@gmail.com> wrote:
>
>> Hi All,
>>
>> Thanks for the responses. I am facing another issue with env variables.
>>
>> I want to register a variable to capture the output of a shell command as 
>> shown below. So far its fine..
>> But I also want to save that command result in a remote environment 
>> variable and that is not working. My playbook is as follows:
>>
>> ----
>> hosts: localhost
>>   tasks:
>>     - name: "subtask"
>>       shell: lsblk --nodeps  | grep disk | wc -l
>>       register: disk_count
>>       environment: "{{ disk_count.stdout }}"
>> -- 
>>
>> --
>> fatal: [localhost]: FAILED! => {"msg": "The field 'environment' has an 
>> invalid value, which includes an undefined variable. The error was: 
>> 'disk_count' is undefined\n\nThe error appears to be in '/root/test.yaml'
>>
>
> This is because the expression in the environment parameter is evaluated 
> before the task, and at that time it is not yet known.
> In general, if you need the output of a command to actually run the 
> command, that seems like a circular dependency to me. 
> Ansible will not help you fix that.
>
>
>

-- 
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/795c8547-c6ca-44a5-beb0-59c50e483e42n%40googlegroups.com.

Reply via email to