Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

homebrew module: task fails on warning message #7044

Closed
1 task done
Fregf opened this issue Jul 31, 2023 · 13 comments · Fixed by #8406
Closed
1 task done

homebrew module: task fails on warning message #7044

Fregf opened this issue Jul 31, 2023 · 13 comments · Fixed by #8406
Labels
bug This issue/PR relates to a bug callback callback plugin has_pr module module plugins plugin (any type)

Comments

@Fregf
Copy link

Fregf commented Jul 31, 2023

Summary

Given this Ansible task:

- community.general.homebrew:
        name:
          - android-studio
          - clion
          - cyberduck
          - intellij-idea-ce
          - keka
          - vscodium
        state: latest

If one of the packages is already the latest version, execution is stopped and the tasks fails:

fatal: [host.example.org]: FAILED! => changed=false 
  msg: 'Warning: Not upgrading android-studio, the latest version is already installed'

I expect this to be a non-fatal warning, and that it continues running the playbook.

Issue Type

Bug Report

Component Name

homebrew

Ansible Version

$ ansible --version
ansible [core 2.14.3]
  config file = /home/frederik/ig-macos/ansible.cfg
  configured module search path = ['/home/frederik/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3/dist-packages/ansible
  ansible collection location = /home/frederik/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/bin/ansible
  python version = 3.11.2 (main, Mar 13 2023, 12:18:29) [GCC 12.2.0] (/usr/bin/python3)
  jinja version = 3.1.2
  libyaml = True

Community.general Version

$ ansible-galaxy collection list community.general

# /home/frederik/.ansible/collections/ansible_collections
Collection        Version
----------------- -------
community.general 3.6.0  

# /usr/lib/python3/dist-packages/ansible_collections
Collection        Version
----------------- -------
community.general 6.4.0  

Configuration

$ ansible-config dump --only-changed
ANSIBLE_NOCOWS(/home/frederik/ig-macos/ansible.cfg) = True
CONFIG_FILE() = /home/frederik/ig-macos/ansible.cfg
DEFAULT_FORKS(/home/frederik/ig-macos/ansible.cfg) = 16
DEFAULT_HOST_LIST(/home/frederik/ig-macos/ansible.cfg) = ['/home/frederik/ig-macos/inventory']
DEFAULT_LOG_PATH(/home/frederik/ig-macos/ansible.cfg) = /home/frederik/ig-macos/ansible.log
DEFAULT_ROLES_PATH(/home/frederik/ig-macos/ansible.cfg) = ['/home/frederik/ig-macos/roles', '/etc/ansible/roles']
DEFAULT_STDOUT_CALLBACK(/home/frederik/ig-macos/ansible.cfg) = yaml
DEFAULT_STRATEGY(/home/frederik/ig-macos/ansible.cfg) = free
DEFAULT_TIMEOUT(/home/frederik/ig-macos/ansible.cfg) = 60

OS / Environment

Debian 12

Steps to Reproduce

- community.general.homebrew:
        name:
          - android-studio
          - clion
          - cyberduck
          - intellij-idea-ce
          - keka
          - vscodium
        state: latest

Expected Results

When one of the packages is already up to date, it continues upgrading the other packages and this tasks succeeds.

Actual Results

fatal: [host.example.org]: FAILED! => changed=false 
  msg: 'Warning: Not upgrading android-studio, the latest version is already installed'

Execution stops at this point.

Code of Conduct

  • I agree to follow the Ansible Code of Conduct
@ansibullbot
Copy link
Collaborator

Files identified in the description:

If these files are incorrect, please update the component name section of the description or use the !component bot command.

click here for bot help

@ansibullbot
Copy link
Collaborator

@ansibullbot ansibullbot added bug This issue/PR relates to a bug callback callback plugin plugins plugin (any type) labels Jul 31, 2023
@felixfontein
Copy link
Collaborator

!component =plugins/modules/homebrew.py

@ansibullbot
Copy link
Collaborator

Files identified in the description:

If these files are incorrect, please update the component name section of the description or use the !component bot command.

click here for bot help

@ansibullbot
Copy link
Collaborator

@ansibullbot ansibullbot added the module module label Jul 31, 2023
@xaethos
Copy link

xaethos commented Aug 21, 2023

I was just having the same issue with visual-studio-code. It was fixed by using the community.general.homebrew_cask module instead, which should apply here too, since android-studio is a Cask, not a Formula.

@dokimyj
Copy link

dokimyj commented Feb 1, 2024

Is this fixed or any other workarounds? I am having the same issue with community.general.homebrew_cask with Temurin8 installation(or skip if exists) still in 2024 Feb

Avoiding with $HOMEBREW_PATH/Caskroom check as workaround.

@HarryWeppner
Copy link

We see a similar failure mode when the intention is to install a formula.

failed: [localhost] (item=docker) => {"ansible_loop_var": "item", "changed": false, "item": "docker", "msg": "Warning: Treating docker as a formula. For the cask, use homebrew/cask/docker or specify the --cask flag."}

What's the recommended approach here?

@gaiazov
Copy link

gaiazov commented Apr 5, 2024

@HarryWeppner seeing the same issue. Tried adding install_options: formula and it didn't help. ignore_errors: true works but is... not ideal

@edv
Copy link

edv commented Apr 7, 2024

We see a similar failure mode when the intention is to install a formula.

failed: [localhost] (item=docker) => {"ansible_loop_var": "item", "changed": false, "item": "docker", "msg": "Warning: Treating docker as a formula. For the cask, use homebrew/cask/docker or specify the --cask flag."}

What's the recommended approach here?

I encounter this same problem, and it seems to be caused by packages that are also available as casks (like awscli, httpie, etc.). I specified the install_options: 'formula' option, but this does not fully resolve the problem.

As a workaround I resolved this locally by doing the following:

  • edit ~/.ansible/collections/ansible_collections/community/general/plugins/modules/homebrew.py
  • modify the code from line 484, by adding --formula, this might be a nice permanent fix, as there is a seperate ansible module for homebrew casks (so maybe everything in this one should be forced to be a formula?).
        cmd = [
            "{brew_path}".format(brew_path=self.brew_path),
            "info",
            "--formula",
            "--json=v2",
            self.current_package,
        ]

@xaethos
Copy link

xaethos commented Apr 9, 2024

this might be a nice permanent fix, as there is a seperate ansible module for homebrew casks (so maybe everything in this one should be forced to be a formula?).

It is a breaking change for anyone who is using this module for casks, though in my mind absolutely worth it. Even using Homebrew CLI directly this duality has been an issue for me.

@egor-lopatin
Copy link

We see a similar failure mode when the intention is to install a formula.

failed: [localhost] (item=docker) => {"ansible_loop_var": "item", "changed": false, "item": "docker", "msg": "Warning: Treating docker as a formula. For the cask, use homebrew/cask/docker or specify the --cask flag."}

What's the recommended approach here?

I encounter this same problem, and it seems to be caused by packages that are also available as casks (like awscli, httpie, etc.). I specified the install_options: 'formula' option, but this does not fully resolve the problem.

As a workaround I resolved this locally by doing the following:

  • edit ~/.ansible/collections/ansible_collections/community/general/plugins/modules/homebrew.py
  • modify the code from line 484, by adding --formula, this might be a nice permanent fix, as there is a seperate ansible module for homebrew casks (so maybe everything in this one should be forced to be a formula?).
        cmd = [
            "{brew_path}".format(brew_path=self.brew_path),
            "info",
            "--formula",
            "--json=v2",
            self.current_package,
        ]

Yeah, that's the issue with the commit: fa30b02#diff-109efc689f4332320bad76472328471ef85a0faeae32ec97086c9790e244c69eR491-R494

^^ @thewalla07

where we start checking error messages (stderr) of the run_command, where the warning message is passed in such a cese.

@edv, I would love if you could create a PR for the fix. Do not want to take your credits ))
I supposed the fix that proposed by you well enough, because I see no options to suppress the warning (--quiet falg does not work for me here) and add some comples statement to ignore this particular message is not elegant as for me.

egor-lopatin added a commit to egor-lopatin/community.general that referenced this issue Apr 16, 2024
egor-lopatin added a commit to egor-lopatin/community.general that referenced this issue Apr 16, 2024
kustodian pushed a commit to kustodian/community.general that referenced this issue May 22, 2024
Instead of checking if there is an error message, which can also be a
warning, we now check the return code.

This commint fixes ansible-collections#8229 ansible-collections#7044
kustodian pushed a commit to kustodian/community.general that referenced this issue May 22, 2024
Instead of checking if there is an error message, which can also be a
warning, we now check the return code.

This commit fixes ansible-collections#8229 ansible-collections#7044
kustodian pushed a commit to kustodian/community.general that referenced this issue May 22, 2024
Instead of checking if there is an error message, which can also be a
warning, we now check the return code.

This commit fixes ansible-collections#8229 ansible-collections#7044
@kustodian
Copy link
Contributor

I added a simple fix for this issue in #8406

kustodian pushed a commit to kustodian/community.general that referenced this issue May 22, 2024
Instead of checking if there is an error message, which can also be a
warning, we now check the return code.

This commit fixes ansible-collections#8229 ansible-collections#7044
kustodian pushed a commit to kustodian/community.general that referenced this issue May 22, 2024
Instead of checking if there is an error message, which can also be a
warning, we now check the return code.

This commit fixes ansible-collections#8229 ansible-collections#7044
kustodian pushed a commit to kustodian/community.general that referenced this issue May 22, 2024
Instead of checking if there is an error message, which can also be a
warning, we now check the return code.

This commit fixes ansible-collections#8229 ansible-collections#7044
kustodian pushed a commit to kustodian/community.general that referenced this issue May 22, 2024
Instead of checking if there is an error message, which can also be a
warning, we now check the return code.

This commit fixes ansible-collections#8229 ansible-collections#7044
kustodian pushed a commit to kustodian/community.general that referenced this issue May 22, 2024
Instead of checking if there is an error message, which can also be a
warning, we now check the return code.

This commit fixes ansible-collections#8229 ansible-collections#7044
felixfontein pushed a commit that referenced this issue May 26, 2024
Instead of checking if there is an error message, which can also be a
warning, we now check the return code.

This commit fixes #8229 #7044

Co-authored-by: Strahinja Kustudic <[email protected]>
patchback bot pushed a commit that referenced this issue May 26, 2024
Instead of checking if there is an error message, which can also be a
warning, we now check the return code.

This commit fixes #8229 #7044

Co-authored-by: Strahinja Kustudic <[email protected]>
(cherry picked from commit 43cb5a0)
felixfontein pushed a commit that referenced this issue May 26, 2024
…g because of warnings (#8425)

Fix the homebrew module failing because of warnings (#8406)

Instead of checking if there is an error message, which can also be a
warning, we now check the return code.

This commit fixes #8229 #7044

Co-authored-by: Strahinja Kustudic <[email protected]>
(cherry picked from commit 43cb5a0)

Co-authored-by: Strahinja Kustudic <[email protected]>
felixfontein pushed a commit to felixfontein/community.general that referenced this issue May 27, 2024
…ons#8406)

Instead of checking if there is an error message, which can also be a
warning, we now check the return code.

This commit fixes ansible-collections#8229 ansible-collections#7044

Co-authored-by: Strahinja Kustudic <[email protected]>
(cherry picked from commit 43cb5a0)
felixfontein added a commit that referenced this issue Jun 1, 2024
#8429)

Fix the homebrew module failing because of warnings (#8406)

Instead of checking if there is an error message, which can also be a
warning, we now check the return code.

This commit fixes #8229 #7044

Co-authored-by: Strahinja Kustudic <[email protected]>
(cherry picked from commit 43cb5a0)

Co-authored-by: Strahinja Kustudic <[email protected]>
Massl123 pushed a commit to Massl123/community.general that referenced this issue Feb 7, 2025
…ons#8406)

Instead of checking if there is an error message, which can also be a
warning, we now check the return code.

This commit fixes ansible-collections#8229 ansible-collections#7044

Co-authored-by: Strahinja Kustudic <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue/PR relates to a bug callback callback plugin has_pr module module plugins plugin (any type)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants