ansible-inventory

Can an Ansible group name contain a hyphen (-)?


Does Ansible dynamic inventory plugin for AWS EC2 allow the character - when naming groups?
From what I see, it changes hyphens (-) to underscores (_) when creating the graph of the inventory.

For example,

groups:
    test-group: "'condition'"

is being represented as

|--@os_cluster:
|  |--ip-10-0-0-00.az.example.com

when using ansible-inventory.


Solution

  • Group names should follow the same guidelines as Creating valid variable names.

    Source: Inventory basics: formats, hosts, and groups

    Then in the linked page:

    Not all strings are valid Ansible variable names. A variable name can only include letters, numbers, and underscores.

    Source: Creating valid variable names

    So, indeed, group names cannot contain hyphens, and this is why Ansible replaces non valid characters by underscores in your group names.