Skip to content

args

This rule validates if the task arguments conform with the plugin documentation.

The rule validation will check if the option name is valid and has the correct value along with conditionals on the options like mutually_exclusive, required_together, required_one_of and so on.

For more information see the argument spec validator topic in the Ansible module utility documentation.

Possible messages:

  • args[module] - missing required arguments: ...
  • args[module] - missing parameter(s) required by ...

Problematic Code

---
- name: Fixture to validate module options failure scenarios
  hosts: localhost
  tasks:
    - name: Clone content repository
      ansible.builtin.git: # <- Required option `repo` is missing.
        dest: /home/www
        accept_hostkey: true
        version: master
        update: false

    - name: Enable service httpd and ensure it is not masked
      ansible.builtin.systemd: # <- Missing 'name' parameter required by 'enabled'.
        enabled: true
        masked: false

    - name: Use quiet to avoid verbose output
      ansible.builtin.assert:
        test:
          - my_param <= 100
          - my_param >= 0
        quiet: invalid # <- Value for option `quiet` is invalid.

    - name: Do not use mutually exclusive arguments together
      ansible.builtin.command:
        cmd: /bin/echo # <- cmd and argv are mutually exclusive options
        argv:
          - Hello
      when_changed: false

Correct Code

---
- name: Fixture to validate module options pass scenario
  hosts: localhost
  tasks:
    - name: Clone content repository
      ansible.builtin.git: # <- Contains required option `repo`.
        repo: https://github.com/ansible/ansible-examples
        dest: /home/www
        accept_hostkey: true
        version: master
        update: false

    - name: Enable service httpd and ensure it is not masked
      ansible.builtin.systemd: # <- Contains 'name' parameter required by 'enabled'.
        name: httpd
        enabled: false
        masked: false

    - name: Use quiet to avoid verbose output
      ansible.builtin.assert:
        that:
          - my_param <= 100
          - my_param >= 0
        quiet: True # <- Has correct type value for option `quiet` which is boolean.

    - name: Do not use mutually exclusive arguments together
      ansible.builtin.command:
        cmd: "/bin/echo Hello" # <- Does not use `cmd` and `argv`
      when_changed: false

    - name: Do not use mutually exclusive arguments together alternative
      ansible.builtin.command:
        argv: # <- Does not use `cmd` and `argv`
          - /bin/echo
          - Hello
      when_changed: false

Special cases

In some complex cases where you are using jinja expressions, the linter may not able to fully validate all the possible values and report a false positive. The example below would usually report parameters are mutually exclusive: src|content but because we added # noqa: args[module] it will just pass.

- name: Copy files # noqa: args[module]
  become: true
  ansible.builtin.copy:
    src: "{{ zj_item['src'] | default(omit) }}"
    content: "{{ zj_item['content'] | default(omit) }}"
    dest: "{{ zj_item['dest'] }}"
    mode: "0644"
  loop: "{{ copy_items }}"
  loop_control:
    loop_var: zj_item