1

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?

U880D
  • 8,601
  • 6
  • 24
  • 40
lonix
  • 14,255
  • 23
  • 85
  • 176
  • 1
    It's documentation. You read it. In this case, the `platform` attribute says `Platform: posix`, so you look at it and it tells you that this module can run on POSIX systems. – flowerysong May 17 '23 at 05:12
  • Putting aside the snarky comment, that doesn't really help. I know for example that `check_mode` and `diff_mode` correspond to CLI switches. So I assume that I can "use" the `platform` attribute as well, somehow - maybe on the CLI or in a play. But I don't know how. I'd like to know whether I can use that attribute to run a task that only targets certain OSs. – lonix May 17 '23 at 05:20
  • 1
    No. Attributes are documentation. The only thing you can do with them is read them. – flowerysong May 17 '23 at 05:21
  • 1
    Here's the original proposal for new structured documentation fields, which ended up being implemented as attributes: https://github.com/ansible/proposals/issues/68 – flowerysong May 17 '23 at 05:32

1 Answers1

1

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 and diff_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 attribure platform: posix means you can't use the module on Windows.

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 ...

U880D
  • 8,601
  • 6
  • 24
  • 40