Each Ansible module's documentation page has an "Attributes" section.
For example, here is the one for the command
module. It has these attributes: check_mode
, diff_mode
, platform
and raw
.
In general, how do I use a module's attributes?
And in this particular example, what is the platform
attribute and how do I use it?
What are Ansible module attributes?
These are documentation only. They describe some of the capabilities and properties of the module.
I know for example that
check_mode
anddiff_mode
correspond to CLI switches.
They mean only that the module which was developed has implemented the capabilities to use check_mode
or diff_mode
. In other words, they state only if check_mode
or diff_mode
"are supported" by the module and if you can take advantage of Using check mode or Using diff mode.
So I assume that I can "use" the
platform
attribute as well,
No, as it states only for which target platform the module was developed. An attribute platform: posix
means you can maybe not use the module on Windows and depending on how it was implemented.
Some background information can be found within the Developer Guide of the Ansible documentation.
I'd like to know whether I can ... run a task that only targets certain OSs.
For such Use Case it is recommended to use Ansible facts and Conditionals based on ansible_facts
, specifically os_family
.
Some References
for Windows targets ...