Ansible Module shell: Difference between revisions
Jump to navigation
Jump to search
(2 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
=External= | =External= | ||
* | * https://docs.ansible.com/ansible/latest/modules/shell_module.html | ||
=Internal= | =Internal= | ||
Line 11: | Line 11: | ||
<syntaxhighlight lang='bash'> | <syntaxhighlight lang='bash'> | ||
ansible -i ./hosts -b --become-user=root all -m shell -a 'ls -al' | ansible -i ./hosts -b --become-user=root all -m shell -a 'ls -al' | ||
</syntaxhighlight> | |||
<syntaxhighlight lang='yaml'> | |||
- name: IDEA application histories | |||
shell: "cat \"{{ item.path }}\"" | |||
with_items: "{{ some_var | list }}" | |||
register: some_other_var | |||
changed_when: false | |||
</syntaxhighlight> | |||
<code>shell</code> can be used to run complex shell pipelines, set/unset environment variables in the execution environment, etc: | |||
<syntaxhighlight lang='yaml'> | |||
- name: test shell | |||
shell: "{ unset JAVA_HOME; /usr/libexec/java_home -v 11; }" | |||
register: execution_result | |||
</syntaxhighlight> | </syntaxhighlight> |
Latest revision as of 19:43, 12 July 2021
External
Internal
Example
ansible -i ./hosts -b --become-user=root all -m shell -a 'ls -al'
- name: IDEA application histories
shell: "cat \"{{ item.path }}\""
with_items: "{{ some_var | list }}"
register: some_other_var
changed_when: false
shell
can be used to run complex shell pipelines, set/unset environment variables in the execution environment, etc:
- name: test shell
shell: "{ unset JAVA_HOME; /usr/libexec/java_home -v 11; }"
register: execution_result