Proper YAML Syntax for Ansible Role Dependencies: Fixing Deprecation Warnings and Syntax Errors


4 views

Ansible has gradually evolved its YAML syntax requirements for role dependencies in meta/main.yml. The old comma-separated format is being phased out in favor of more explicit YAML structures. This change affects both local role references and Galaxy-installed roles.

The most robust way to define dependencies that works across all recent Ansible versions is:

dependencies:
  - name: 030.sensu-install
    src: 030.sensu-install
    version: 0.1.0
    scm: git

Or for local roles:

dependencies:
  - name: local-role
    src: ../relative/path/to/role

Using both name and src satisfies:

  1. Ansible's requirement for a role name in metadata
  2. Galaxy's expectation of source specification
  3. Future compatibility with newer Ansible versions

Here's a production-tested meta/main.yml example:

---
dependencies:
  - name: common-role
    src: git+https://github.com/org/common-role.git
    version: v1.2.3
  - name: monitoring
    src: ../monitoring-role
  - name: database-setup
    src: geerlingguy.mysql
    version: 3.3.0
galaxy_info:
  author: Your Name
  description: Example role with proper dependencies
  license: MIT

When working with versioned roles from Galaxy:

dependencies:
  - name: nginx
    src: geerlingguy.nginx
    version: ">=2.0.0,<3.0.0"

If you encounter:

  • Deprecation warnings: Ensure you're not using the old {role: name} syntax
  • Syntax errors: Verify all required fields (name/src) are present
  • Installation failures: Check network connectivity and repository accessibility

Many Ansible users encounter deprecation warnings when using the old comma-separated role specification format:

dependencies:
  - { role: 030.sensu-install }

This triggers the warning:

[DEPRECATION WARNING]: The comma separated role spec format, use the
yaml/explicit format instead..
This feature will be removed in a future release.

The modern approach requires either the role: or src: key with proper YAML structure. However, these approaches behave differently:

Using role: syntax

dependencies:
  - role: 030.sensu-install
    version: 0.1.0

This passes syntax check but still shows the deprecation warning in some cases.

Using src: syntax

dependencies:
  - src: 030.sensu-install
    version: 0.1.0

This solves the deprecation warning but may fail syntax check with:

ERROR! role definitions must contain a role name

The most reliable approach combines both specifications:

dependencies:
  - name: sensu-install
    src: 030.sensu-install
    version: 0.1.0

This format:

  • Eliminates deprecation warnings
  • Passes syntax checks
  • Provides clear role identification
  • Maintains version control

The complete specification varies based on the role source:

Galaxy roles

dependencies:
  - name: geerlingguy.nginx
    src: geerlingguy.nginx
    version: 3.0.0

Git repository roles

dependencies:
  - name: custom-role
    src: https://github.com/user/repo.git
    version: master
    scm: git

Local roles

dependencies:
  - name: local-role
    src: ../path/to/role
  • Always include the name field for clarity
  • Specify versions explicitly when possible
  • For Galaxy roles, use the full namespace (username.rolename)
  • Test your syntax with ansible-galaxy install -r requirements.yml --force