Ansible Module command: Difference between revisions
Jump to navigation
Jump to search
Line 27: | Line 27: | ||
=Setting Facts as Result of a Command= | =Setting Facts as Result of a Command= | ||
This sets a [[Ansible_Concepts#Fact|fact]]: | |||
<syntaxhighlight lang='yaml'> | |||
- name: Read required JDK version | |||
command: "sh -c \"finger `whoami` | awk -F: '{ print $3 }' | head -n1 | sed 's/^ //'\"" | |||
register: name_cmd | |||
changed_when: false | |||
when: name is not defined | |||
</syntaxhighlight> |
Revision as of 02:18, 30 December 2020
External
Internal
Overview
The command module takes the command name followed by a list of space-delimited arguments.
A command will NOT be interpreted by a shell, so variables like $HOME and operations like "<", ">", "|", ";" and "&" will not work. Use the shelll module for that.
- name: A command example
command: some-command arg1 arg2
become: true
become_user: root
args:
chdir: /somedir/
"become" and "become_user" are optional. Also see:
Setting Facts as Result of a Command
This sets a fact:
- name: Read required JDK version
command: "sh -c \"finger `whoami` | awk -F: '{ print $3 }' | head -n1 | sed 's/^ //'\""
register: name_cmd
changed_when: false
when: name is not defined