Make the scope of "command_result" playbook-wide with "set_fact". Registered
variables belong to the host which is running the play. i.e. "localhost" in
your case. The second play runs "remotehost" who know nothing about varaibles
registered by "localhost".
I tried the set_fact suggestion but seems I need more help / understanding.
Below is the error i get:
FAILED! => {“msg”: "The task includes an option with an undefined variable. The error was: ‘command_result’ is undefined\n\nThe error appears to be in ‘/app/rollback.yml’: line 88, column 6, but may\nbe elsewhere in the file depending on the exact syntax problem.
Below is my updated playbook:
`
name: Play 1
hosts: localhost
tasks:
name: “Collect Output”
command: ls -ltr *
register: command_result
The solution given with “my_list” is complaining of the below error:
FAILED! => {“msg”: "The task includes an option with an undefined variable. The error was: ‘dict object’ has no attribute ‘results’\n\nThe error appears to be in
Guess we need to relook at this proposed code snippet: