-3

I'm using Python 3.10.1 and I've installed Ansible using PIP version 21.2.4

ansible --version returns the following

ansible [core 2.12.1]
  config file = /Users/user_name/Projects/support/ansible/ansible.cfg
  configured module search path = ['/Users/user_name/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /Users/user_name/.pyenv/versions/3.10.1/lib/python3.10/site-packages/ansible
  ansible collection location = /Users/user_name/.ansible/collections:/usr/share/ansible/collections
  executable location = /Users/user_name/.pyenv/versions/3.10.1/bin/ansible
  python version = 3.10.1 (main, Jan  3 2022, 06:39:07) [Clang 13.0.0 (clang-1300.0.29.30)]
  jinja version = 3.0.3
  libyaml = True

In my playbook, I'm able to run all of the tasks except for any shell or command module call which has the ignore errors directive.

Here's the offending entry:

  - name: RBENV init
    become_user: deploy
    become: true
    command:
      chdir: /home/deploy/
      cmd: rbenv init
      ignore_errors: yes

Which returns:

FAILED! => {"changed": false, "msg": "Unsupported parameters for (ansible.legacy.command) module: ignore_errors. Supported parameters include: warn, strip_empty_ends, _uses_shell, argv, _raw_params, chdir, creates, stdin, removes, executable, stdin_add_newline."}

What's interesting is that if I remove ignore_errors: yes the command executes but then chokes on the non-zero response rbenv init returns.

I'm brand new to Ansible and and when I google that error message I get posts from like 5 and 6 years ago where the user is using an at the time outdated version of Ansible. Am I using the current version? How would I determine this?

AndrewGB
  • 16,126
  • 5
  • 18
  • 49
greyoxide
  • 1,197
  • 1
  • 17
  • 45

1 Answers1

3

According the documentation of Error handling in playbooks and the error message

Unsupported parameters for (ansible.legacy.command) module: ignore_errors. Supported parameters include: warn, strip_empty_ends, _uses_shell, argv, _raw_params, chdir, creates, stdin, removes, executable, stdin_add_newline.

your indents are incorrect. So the error is just caused by a typo and you may use instead

- name: RBENV init
  become_user: deploy
  become: true
  command:
    chdir: /home/deploy/
    cmd: rbenv init
  ignore_errors: yes

You may also have a look into whats the difference between ansible raw, shell and command?

Quote: "It can be used if you want to execute more complex commands, for example commands concatenated with pipes".

Regarding

... but then chokes on the non-zero response rbenv init returns.

and in general for your command, you may introduce failed_when instead of ignoring errors at all.

U880D
  • 8,601
  • 6
  • 24
  • 40
  • thanks @U880D that did it. After seeing your response and reading the documentation again I can see that `ignore_errors` is a parameter for the task itself and not just the command module. thank you again. – greyoxide Jan 03 '22 at 17:03