You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
register is also supported in Ansible. you use it not just for templates context, but for conditionals in the task itself using when: and probably others.
- hosts: web_servers
tasks:
- name: Run a shell command and register its output as a variable
ansible.builtin.shell: /usr/bin/foo
register: foo_result
ignore_errors: true
- name: Run a shell command using output of the previous task
ansible.builtin.shell: /usr/bin/bar
when: foo_result.rc == 5
The struct for vars created with register are kind of complex in a way which I'm not a huge fan of, but exit status (registered_var.rc) and stdout separate from stderr is very useful.
rash-sh
allows passing arbitrary values from one task to another one via register (see here)Starting from the above we can go further and allow multiple named returns
This design has sufficient level of indirection to avoid any name collisions. Also it doesn't pollute the global namespace.
The text was updated successfully, but these errors were encountered: