<div dir="ltr">
<div>Pavel's approach should work fine. Here are two other approaches I've seen used.<br></div><div><br></div><div>1.
 Run a playbook that installs the enable script 
(/opt/rh/devtoolset-8/enable) into /etc/profile.d. Then, in another 
playbook do the stuff you want to do. The second playbook will run as a 
new ssh login which means it will pick up the enable actions from the 
/etc/profile.d/ script. If you do this, you also need to fix the 
devtoolset sudo script because it's broken and doesn't properly forward 
arguments to the actual sudo program. I have a working version.<br></div><div>2.
 Install the devtoolset tools you want then configure the system using 
the "alternatives" program to make it so that the devtoolset versions 
are the ones that are run. The ansible module for alternatives doesn't 
work great though. Specifically, it won't update the settings once 
they've been set, or if it does, I couldn't easily figure out how.</div>

</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Oct 11, 2019 at 7:35 AM Pavel Valena <<a href="mailto:pvalena@redhat.com">pvalena@redhat.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">----- Original Message -----<br>
> From: <a href="mailto:viscapi@cines.fr" target="_blank">viscapi@cines.fr</a><br>
> To: <a href="mailto:sclorg@redhat.com" target="_blank">sclorg@redhat.com</a><br>
> Cc: "caux" <<a href="mailto:caux@cines.fr" target="_blank">caux@cines.fr</a>><br>
> Sent: Friday, October 11, 2019 11:22:46 AM<br>
> Subject: [<a href="http://scl.org" rel="noreferrer" target="_blank">scl.org</a>] SCL and Ansible ?<br>
> <br>
> Dear all,<br>
> <br>
> Silly question: is there a way to call "scl enable" from within an Ansible<br>
> role ?<br>
> <br>
> So far we've been trying the command, shell and scripts modules, but to no<br>
> avail...<br>
> <br>
> <a href="https://docs.ansible.com/ansible/latest/modules/command_module.html#command-module" rel="noreferrer" target="_blank">https://docs.ansible.com/ansible/latest/modules/command_module.html#command-module</a><br>
> <a href="https://docs.ansible.com/ansible/latest/modules/shell_module.html#shell-module" rel="noreferrer" target="_blank">https://docs.ansible.com/ansible/latest/modules/shell_module.html#shell-module</a><br>
> <a href="https://docs.ansible.com/ansible/latest/modules/script_module.html#script-module" rel="noreferrer" target="_blank">https://docs.ansible.com/ansible/latest/modules/script_module.html#script-module</a><br>
> <br>
> Here are some failed attempts:<br>
> <br>
> - name: Start using the software collection for maven<br>
>   shell: scl_enabled rh-maven35<br>
>   register: swap_exists<br>
>   ignore_errors: true<br>
> #script: test.sh<br>
>  # shell: scl enable /etc/scl/conf//opt/rh/rh-maven35 bash && echo toto<br>
>  #shell: /usr/bin/scl enable rh-maven35 bash<br>
>  # args:<br>
>  #   warn: yes<br>
>  #   chdir: "{{ path_to_pastis }}"<br>
>   #easy_install:<br>
>   #  name: scl<br>
> #  args:<br>
> #    executable: "/usr/bin/scl enable rh-maven35 bash"<br>
>  # command: |<br>
>  #   /usr/bin/scl enable rh-maven35 bash<br>
> #bash<br>
>  # shell: |<br>
>  #   scl enable rh-maven35 bash<br>
> #bash<br>
> #  args:<br>
> #    executable: /bin/bash<br>
<br>
Hello,<br>
<br>
I'm no ansible expert, but couldn't you run the command you wan't like so:<br>
<br>
  shell: /usr/bin/scl enable rh-maven35 -- /path/to/prog/or/scriplet arguments... <br>
<br>
<br>
Alternatively, though unsupported probably, you could try `. scl_source`; f.e.:<br>
<br>
```<br>
$ ruby -v ; . scl_source enable rh-ruby25 ; ruby -v<br>
ruby 2.0.0p648 (2015-12-16) [x86_64-linux]<br>
ruby 2.5.5p157 (2019-03-15 revision 67260) [x86_64-linux]<br>
<br>
```<br>
<br>
HIH,<br>
Pavel<br>
<br>
> <br>
> I think the root issue is that, as far as I understand, "scl enable" starts a<br>
> new shell and sources environment variables in there, while Ansible is still<br>
> waiting for some RC in the parent shell. Thus Ansible is not really failing,<br>
> but just keeps on waiting for ever...<br>
> <br>
> Any help would be greatly appreciated.<br>
> <br>
> Best regards,<br>
> <br>
> Samuel from CINES<br>
> <br>
> <a href="https://www.cines.fr/en/" rel="noreferrer" target="_blank">https://www.cines.fr/en/</a><br>
> <br>
> --<br>
> <br>
> Samuel VISCAPI<br>
> <br>
> +33(0)4 67 14 14 36<br>
> <a href="mailto:viscapi@cines.fr" target="_blank">viscapi@cines.fr</a><br>
> IM: sviscapi (Skype)<br>
> <br>
<br>
-- <br>
Pavel Valena<br>
Software Engineer, Red Hat<br>
Brno, Czech Republic<br>
<br>
_______________________________________________<br>
SCLorg mailing list<br>
<a href="mailto:SCLorg@redhat.com" target="_blank">SCLorg@redhat.com</a><br>
<a href="https://www.redhat.com/mailman/listinfo/sclorg" rel="noreferrer" target="_blank">https://www.redhat.com/mailman/listinfo/sclorg</a><br>
</blockquote></div>