<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
p.msonormal0, li.msonormal0, div.msonormal0
        {mso-style-name:msonormal;
        mso-margin-top-alt:auto;
        margin-right:0in;
        mso-margin-bottom-alt:auto;
        margin-left:0in;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
span.EmailStyle18
        {mso-style-type:personal-reply;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri",sans-serif;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal">If you want scl enable to effect the ansible process itself, you could write a python function that parses the enable script using shutil and then sets the environment variables on os.environ.  Then, expose this as an ansible plugin.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<div style="border:none;border-left:solid blue 1.5pt;padding:0in 0in 0in 4.0pt">
<div>
<div style="border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b>From:</b> sclorg-bounces@redhat.com <sclorg-bounces@redhat.com>
<b>On Behalf Of </b>Rob Wissmann<br>
<b>Sent:</b> Friday, October 11, 2019 9:33 AM<br>
<b>To:</b> Pavel Valena <pvalena@redhat.com><br>
<b>Cc:</b> caux <caux@cines.fr>; sclorg@redhat.com<br>
<b>Subject:</b> Re: [scl.org] SCL and Ansible ?<o:p></o:p></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<div>
<p class="MsoNormal">Pavel's approach should work fine. Here are two other approaches I've seen used.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">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.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">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.<o:p></o:p></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<div>
<p class="MsoNormal">On Fri, Oct 11, 2019 at 7:35 AM Pavel Valena <<a href="mailto:pvalena@redhat.com">pvalena@redhat.com</a>> wrote:<o:p></o:p></p>
</div>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in">
<p class="MsoNormal">----- 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" 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" 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" 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" 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/" 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" target="_blank">https://www.redhat.com/mailman/listinfo/sclorg</a><o:p></o:p></p>
</blockquote>
</div>
</div>
</div>
</body>
</html>