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

Cask installs that require a password fail #29403

Closed
ansibot opened this issue Sep 11, 2017 · 9 comments · Fixed by #46471
Closed

Cask installs that require a password fail #29403

ansibot opened this issue Sep 11, 2017 · 9 comments · Fixed by #46471
Labels
affects_2.2 This issue/PR affects Ansible v2.2 bug This issue/PR relates to a bug. macos macOS community module This issue/PR relates to a module. support:community This issue/PR relates to code supported by the Ansible community.

Comments

@ansibot
Copy link
Contributor

ansibot commented Sep 11, 2017

From @edrozenberg on 2016-11-10T01:31:53Z

ISSUE TYPE
  • Bug Report
COMPONENT NAME

homebrew_cask

ANSIBLE VERSION
ansible 2.2.0.0
  config file = 
  configured module search path = Default w/o overrides
CONFIGURATION
[defaults]
inventory             = hosts/hosts
vault_password_file   = ~/.ansible/vault/password.txt
retry_files_enabled   = False
retry_files_save_path = ~/.ansible/retry
remote_user           = root
nocows                = 0

[ssh_connection]
pipelining = True
OS / ENVIRONMENT

macOS Sierra 10.12.1 (16B2555)

One mac (controller) controlling another mac (minion) using normal ssh connection with ssh key.

SUMMARY

Some homebrew casks ask for a password during the installation process. It appears the ansible module does not provide a way to collect a password and pass it to the homebrew cask installer.

Currently, these casks that require a password need to be manually installed using 'brew cask install at the command line. Ansible cannot install them.

Found two casks so far that failed to install with Ansible, but work fine when done manually: microsoft-office and wireshark

STEPS TO REPRODUCE
- homebrew_cask: name=wireshark state=present
- homebrew_cask: name=microsoft-office state=present
EXPECTED RESULTS

wireshark cask and microsoft-office casks are installed

ACTUAL RESULTS
failed: [10.0.1.119] (item=wireshark) => {"failed": true, "item": "wireshark", "msg": "Error: Command failed to execute!\n\n==> Failed command:\n/usr/bin/sudo -E -- /usr/sbin/installer -pkg #<Pathname:/usr/local/Caskroom/wireshark/2.2.1/Wireshark 2.2.1 Intel 64.pkg> -target /\n\n==> Standard Output of failed command:\n\n\n==> Standard Error of failed command:\nsudo: no tty present and no askpass program specified\n\n\n==> Exit status of failed command:\n#<Process::Status: pid 29235 exit 1>"}
failed: [10.0.1.119] (item=microsoft-office) => {"failed": true, "item": "microsoft-office", "msg": "Error: Command failed to execute!\n\n==> Failed command:\n/usr/bin/sudo -E -- /usr/sbin/installer -pkg #<Pathname:/usr/local/Caskroom/microsoft-office/15.27.0_161010/Microsoft_Office_2016_15.27.0_161010_Installer.pkg> -target /\n\n==> Standard Output of failed command:\n\n\n==> Standard Error of failed command:\nsudo: no tty present and no askpass program specified\n\n\n==> Exit status of failed command:\n#<Process::Status: pid 12059 exit 1>"}

Copied from original issue: ansible/ansible-modules-extras#3415

@ansibot
Copy link
Contributor Author

ansibot commented Sep 11, 2017

From @edrozenberg on 2016-11-10T01:31:53Z

Found that the issue has been discussed on homebrew cask, puppet, chef projects already:
Homebrew/homebrew-cask#5667
boxen/puppet-brewcask#22
kitchenplan/chef-homebrewalt#8

Some suggestions are to use sudo, but that would make the entire app owned by root instead of the regular user. Not sure if the issue needs to be tackled by the Ansible cask module or the homebrew cask project.

@ansibot
Copy link
Contributor Author

ansibot commented Sep 11, 2017

From @ansibot on 2016-11-10T01:31:53Z

@indrajitr, ping. This issue is waiting on your response.
click here for bot help

@ansibot
Copy link
Contributor Author

ansibot commented Sep 11, 2017

From @bcg62 on 2016-11-10T01:31:53Z

sous-chefs/homebrew#111

@ansibot
Copy link
Contributor Author

ansibot commented Sep 11, 2017

From @rqelibari on 2016-11-10T01:31:53Z

You can currently circumvent this by doing it like this:

- name: "Run this task before homebrew_cask module, so that sudo cache gets refreshed."
  command: "echo none"
  become: yes

- name: "Install casks."
  homebrew_cask: name={{package}} state=present
  with_items: "{{ your_cask_apps_which_need_admin_rights }}"
  ignore_errors: yes
  loop_control:
     loop_var: package

What this actually does is nothing else then sudo -v does in bash scripts. And as such homebrew-cask will not ask you for a password.

@ansibot
Copy link
Contributor Author

ansibot commented Sep 11, 2017

@ansibot ansibot added affects_2.2 This issue/PR affects Ansible v2.2 bug_report module This issue/PR relates to a module. needs_triage Needs a first human triage before being processed. support:community This issue/PR relates to code supported by the Ansible community. labels Sep 11, 2017
@jborean93 jborean93 removed the needs_triage Needs a first human triage before being processed. label Sep 13, 2017
@gusc
Copy link

gusc commented Dec 15, 2017

It looks like this workaround won't help when, for example installing java on a slower network connection - the sudo from the first call would timeout and ask a password when download finishes and sudo -E installer ... is launched.

@ansibot ansibot added bug This issue/PR relates to a bug. and removed bug_report labels Mar 1, 2018
@edrozenberg
Copy link
Contributor

A few years later I've finally tackled this and found a solution via the use of a SUDO_ASKPASS env var now supported by Homebrew. No other approaches have worked.

Solution posted at:
geerlingguy/ansible-role-homebrew#73 (comment)

craigfurman added a commit to craigfurman/ansible-home that referenced this issue Aug 29, 2018
By using a hideous pre-ansible hook, due to
ansible/ansible#29403
@ansibot ansibot added support:core This issue/PR relates to code supported by the Ansible Engineering Team. and removed support:community This issue/PR relates to code supported by the Ansible community. labels Sep 16, 2018
@ansibot ansibot added needs_maintainer Ansibot is unable to identify maintainers for this PR. (Check `author` in docs or BOTMETA.yml) support:community This issue/PR relates to code supported by the Ansible community. and removed support:core This issue/PR relates to code supported by the Ansible Engineering Team. labels Oct 2, 2018
@danieljaouen
Copy link
Contributor

I'm currently looking into the issue. Once #13620 is merged into devel, that should do the trick. All you would need to do once that happens is add a live: true to the associated task.

@danieljaouen
Copy link
Contributor

danieljaouen commented Oct 3, 2018

Can everyone who still has this issue run a brew --version and an ansible --version for me? I'm looking into this issue, but I'm having problems replicating it with the latest Ansible and Homebrew.

danieljaouen added a commit to danieljaouen/ansible that referenced this issue Oct 4, 2018
@ansibot ansibot removed the needs_maintainer Ansibot is unable to identify maintainers for this PR. (Check `author` in docs or BOTMETA.yml) label Nov 10, 2018
samdoran pushed a commit that referenced this issue Jan 21, 2019
* Fixes #29403: homebrew_cask: Add SUDO_ASKPASS to module.run_command

* homebrew_cask: refactor sudo_password code

* homebrew_cask: more refactoring

* homebrew_cask: use %s instead of string addition
knumskull pushed a commit to knumskull/ansible that referenced this issue Jan 21, 2019
* Fixes ansible#29403: homebrew_cask: Add SUDO_ASKPASS to module.run_command

* homebrew_cask: refactor sudo_password code

* homebrew_cask: more refactoring

* homebrew_cask: use %s instead of string addition
@dagwieers dagwieers added the macos macOS community label Jan 27, 2019
@ansible ansible locked and limited conversation to collaborators Jul 22, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.2 This issue/PR affects Ansible v2.2 bug This issue/PR relates to a bug. macos macOS community module This issue/PR relates to a module. support:community This issue/PR relates to code supported by the Ansible community.
Projects
None yet
6 participants