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

Calling opam commands in Ansible doesn't work well; not sending exit? #4102

Closed
kmahelona opened this issue Mar 1, 2020 · 5 comments
Closed

Comments

@kmahelona
Copy link

I'm installing ocaml packages using opam via Ansible. I don't know what's wrong... I don't think opam returns the correct exit signal or something because Ansible always hangs when trying to do opam commands. If I cancel the deploy then run it again it works because the second time around the package already exists and that time opam gives the correct exit signal.

For example, this simply runs these commands on the machine:

- name: Install ocaml stuff
  become: false
  shell: "{{item}}"
  with_items:
    - opam init -a
    - opam switch create 4.09.0 | true
    - opam install -y dune

Even with the auto/yes flags it still hangs. I don't even get a timeout from Ansible which suggests something is still open? I cancel the Ansible deploy, then run this again, and it get success output like,

init: User configuration:  ~/.profile is already up-to-date.
switch: [ERROR] There already is an installed switch named 4.09.0 # the | true allows this to work

It's likely this is more of an "ansible" thing, but simply running shell: echo test works as expected - the command doesn't hang. So I feel like opam should do something else once it's finished successfully installing or initialising things.

Thanks,
Keoni.

@rjbou
Copy link
Collaborator

rjbou commented Mar 3, 2020

Thanks for the report!

Do you know what is the exact command that keep alive? Unless there is user interaction (confirm of some actions), opam always exits wit some predefined value. On the second run, switch seems to be already created (does package is well installed?), so maybe there is an unanswered question that keep it alive (you don't pass the -y option to switch creation).

@kmahelona
Copy link
Author

Interesting. I'd have to investigate further. There's definitely no errors occurring, and I'd assume anything with a -y (yes) or -f (force) or -a (auto) or --no-user-input-required should return 0 unless there's an error. From a clean install, this definitely hangs on opam init -a and the thing is I can't get the stdout from anisble.

@rjbou
Copy link
Collaborator

rjbou commented Mar 4, 2020

From a clean env, with -a option, init shouldn't indeed ask question, unless something unexpected happens. I don't see what... maybe initial switch that fails, and ask you to wipe or no ? you can try to set up OPAMYES=1 for all command, or give the yes option to opam init.
But, If it hangs on init, how a 4.09.0 switch is already present (on second run) ? At init, the default switch is created according system ocaml and is named default.

@dra27
Copy link
Member

dra27 commented Jul 8, 2021

This should be resolvable with either adding OPAMYES=true to the environment everywhere and/or ensuring -y is on the commands. Please re-open if the issue's still present...

@dra27 dra27 closed this as completed Jul 8, 2021
@Termina1
Copy link

Termina1 commented May 6, 2022

Have both OPAMYES and -y everywhere, but this issue persists. However, due to ansible very complicated command execution scheme, I have no idea what's causing the problem. It seems for some reason ansible cant detect opam command completion.

The only thing I managed to find is that if opam wants to install packages via apt — it ignores opamyes and -y completely: you have to enter y for opam and also y for apt installation. May be this is the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants