[scl.org] SCL and Ansible ?

viscapi at cines.fr viscapi at cines.fr
Tue Oct 15 13:30:53 UTC 2019


Hi Pavel,

Sorry for the late reply.

Your suggestion is indeed working :)

TASK [scl-test : debug] ********************************************************
ok: [sandbox55-adm.cines.fr] => {
    "msg": {
        "changed": true, 
        "cmd": [
            "scl", 
            "enable", 
            "rh-maven35", 
            "--", 
            "mvn", 
            "--version"
        ], 
        "delta": "0:00:00.578223", 
        "end": "2019-10-15 15:28:40.646710", 
        "failed": false, 
        "rc": 0, 
        "start": "2019-10-15 15:28:40.068487", 
        "stderr": "", 
        "stderr_lines": [], 
        "stdout": "\u001b[1mApache Maven 3.5.0 (Red Hat 3.5.0-4.3)\u001b[m\nMaven home: /opt/rh/rh-maven35/root/usr/share/maven\nJava version: 1.8.0_222, vendor: Oracle Corporation\nJava home: /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.222.b10-1.el7_7.x86_64/jre\nDefault locale: fr_FR, platform encoding: UTF-8\nOS name: \"linux\", version: \"3.10.0-1062.1.1.el7.x86_64\", arch: \"amd64\", family: \"unix\"", 
        "stdout_lines": [
            "\u001b[1mApache Maven 3.5.0 (Red Hat 3.5.0-4.3)\u001b[m", 
            "Maven home: /opt/rh/rh-maven35/root/usr/share/maven", 
            "Java version: 1.8.0_222, vendor: Oracle Corporation", 
            "Java home: /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.222.b10-1.el7_7.x86_64/jre", 
            "Default locale: fr_FR, platform encoding: UTF-8", 
            "OS name: \"linux\", version: \"3.10.0-1062.1.1.el7.x86_64\", arch: \"amd64\", family: \"unix\""
        ]
    }
}

Thanks a lot for your help !

Cheers, Samuel

--

Samuel VISCAPI

+33(0)4 67 14 14 36
viscapi at cines.fr
IM: sviscapi (Skype)

----- Mail original -----
De: "Pavel Valena" <pvalena at redhat.com>
À: "viscapi" <viscapi at cines.fr>
Cc: "Petr Hracek" <phracek at redhat.com>, "caux" <caux at cines.fr>, "sclorg" <sclorg at redhat.com>
Envoyé: Mardi 15 Octobre 2019 15:02:54
Objet: Re: [scl.org] SCL and Ansible ?

----- Original Message -----
> From: viscapi at cines.fr
> To: "Petr Hracek" <phracek at redhat.com>
> Cc: "caux" <caux at cines.fr>, "sclorg" <sclorg at redhat.com>
> Sent: Tuesday, October 15, 2019 2:17:15 PM
> Subject: Re: [scl.org] SCL and Ansible ?
> 
> Hi all,
> 
> @Petr: we are running the playbook from the shell. Launching "scl enable"
> through the shell / command / script modules doesn't work AFAIK (Ansible
> never returns). Last week I tried sourcing /opt/rh/rh-maven35/enable, and it
> seems to be roughly equivalent to running "scl enable". Thus I compared the
> environment variables before and after sourcing that file, and came up with
> this:

Hello,

sorry to repeat myself, but couldn't you simply run the following?

```
   command: scl enable rh-maven35 -- maven --version

```

If it fails, what's the output?

Alternatively, could you change the shell used to run a custom one, like we do in container images?

  https://github.com/sclorg/s2i-base-container/blob/master/core/Dockerfile#L35
  https://github.com/sclorg/s2i-ruby-container/blob/master/2.5/root/opt/app-root/etc/scl_enable

Cheers,
Pavel

> 
> - name: check version maven
>   command: /opt/rh/rh-maven35/root/usr/bin/mvn --version
>   environment:
>     MANPATH: "/opt/rh/rh-maven35/root/usr/share/man"
>     JAVACONFDIRS: "/opt/rh/rh-maven35/root/etc/java"
>     XDG_CONFIG_DIRS: "/opt/rh/rh-maven35/root/etc/xdg:/etc/xdg"
>     PATH: "/opt/rh/rh-maven35/root/usr/bin:{{ ansible_env.PATH }}"
>     PYTHONPATH: "/opt/rh/rh-maven35/root/usr/lib/python2.7/site-packages"
>     XDG_DATA_DIRS:
>     "/opt/rh/rh-maven35/root/usr/share:/usr/local/share:/usr/share"
>   register: version
> 
> - debug:
>     msg: '{{ version }}'
> 
> And the output reads as follows:
> 
> TASK [scl-test : debug]
> ********************************************************
> ok: [sandbox55-adm.cines.fr] => {
>     "msg": {
>         "changed": true,
>         "cmd": [
>             "/opt/rh/rh-maven35/root/usr/bin/mvn",
>             "--version"
>         ],
>         "delta": "0:00:01.864600",
>         "end": "2019-10-15 12:15:03.549450",
>         "failed": false,
>         "rc": 0,
>         "start": "2019-10-15 12:15:01.684850",
>         "stderr": "",
>         "stderr_lines": [],
>         "stdout": "\u001b[1mApache Maven 3.5.0 (Red Hat
>         3.5.0-4.3)\u001b[m\nMaven home:
>         /opt/rh/rh-maven35/root/usr/share/maven\nJava version: 1.8.0_222,
>         vendor: Oracle Corporation\nJava home:
>         /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.222.b10-1.el7_7.x86_64/jre\nDefault
>         locale: fr_FR, platform encoding: UTF-8\nOS name: \"linux\",
>         version: \"3.10.0-1062.1.1.el7.x86_64\", arch: \"amd64\", family:
>         \"unix\"",
>         "stdout_lines": [
>             "\u001b[1mApache Maven 3.5.0 (Red Hat 3.5.0-4.3)\u001b[m",
>             "Maven home: /opt/rh/rh-maven35/root/usr/share/maven",
>             "Java version: 1.8.0_222, vendor: Oracle Corporation",
>             "Java home:
>             /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.222.b10-1.el7_7.x86_64/jre",
>             "Default locale: fr_FR, platform encoding: UTF-8",
>             "OS name: \"linux\", version: \"3.10.0-1062.1.1.el7.x86_64\",
>             arch: \"amd64\", family: \"unix\""
>         ]
>     }
> }
> 
> Looks like I can run Maven 3.5 with the correct environment variables that
> way. The problem is that this workaround just doesn't scale, as we'd have to
> analyse the "enable" script coming with every SCL package. At first I
> thought I could just store the contents of that script in an Ansible
> variable and pipe it to some Ansible filters ( | to_yaml for example),
> hoping it would automagically turn my Bash variables into Ansible
> variables...
> 
> https://docs.ansible.com/ansible/latest/user_guide/playbooks_filters.html
> 
> I was obviously wrong...
> 
> Opinions are welcome :)
> 
> Cheers, Samuel
> 
> --
> 
> Samuel VISCAPI
> 
> +33(0)4 67 14 14 36
> viscapi at cines.fr
> IM: sviscapi (Skype)
> 
> ----- Mail original -----
> De: "Petr Hracek" <phracek at redhat.com>
> À: "viscapi" <viscapi at cines.fr>
> Cc: "sclorg" <sclorg at redhat.com>, "caux" <caux at cines.fr>
> Envoyé: Lundi 14 Octobre 2019 10:36:53
> Objet: Re: [scl.org] SCL and Ansible ?
> 
> Hi Samuel,
> 
> I have been writing a couple of ansible-playbooks but did not try it with
> SCL.
> You playbook w/o comments look good.
> 
> But I don't understand the scenario.
> How do you run the ansible-playbook?
> >From container or from shell?
> 
> Can you please give a reproducer steps, so I can analyze it?
> 
> Greetings
>      Petr
> 
> 
> pá 11. 10. 2019 v 11:23 odesílatel <viscapi at cines.fr> napsal:
> 
> > Dear all,
> >
> > Silly question: is there a way to call "scl enable" from within an Ansible
> > role ?
> >
> > So far we've been trying the command, shell and scripts modules, but to no
> > avail...
> >
> >
> > https://docs.ansible.com/ansible/latest/modules/command_module.html#command-module
> >
> > https://docs.ansible.com/ansible/latest/modules/shell_module.html#shell-module
> >
> > https://docs.ansible.com/ansible/latest/modules/script_module.html#script-module
> >
> > Here are some failed attempts:
> >
> > - name: Start using the software collection for maven
> >   shell: scl_enabled rh-maven35
> >   register: swap_exists
> >   ignore_errors: true
> > #script: test.sh
> >  # shell: scl enable /etc/scl/conf//opt/rh/rh-maven35 bash && echo toto
> >  #shell: /usr/bin/scl enable rh-maven35 bash
> >  # args:
> >  #   warn: yes
> >  #   chdir: "{{ path_to_pastis }}"
> >   #easy_install:
> >   #  name: scl
> > #  args:
> > #    executable: "/usr/bin/scl enable rh-maven35 bash"
> >  # command: |
> >  #   /usr/bin/scl enable rh-maven35 bash
> > #bash
> >  # shell: |
> >  #   scl enable rh-maven35 bash
> > #bash
> > #  args:
> > #    executable: /bin/bash
> >
> > I think the root issue is that, as far as I understand, "scl enable"
> > starts a new shell and sources environment variables in there, while
> > Ansible is still waiting for some RC in the parent shell. Thus Ansible is
> > not really failing, but just keeps on waiting for ever...
> >
> > Any help would be greatly appreciated.
> >
> > Best regards,
> >
> > Samuel from CINES
> >
> > https://www.cines.fr/en/
> >
> > --
> >
> > Samuel VISCAPI
> >
> > +33(0)4 67 14 14 36
> > viscapi at cines.fr
> > IM: sviscapi (Skype)
> >
> > _______________________________________________
> > SCLorg mailing list
> > SCLorg at redhat.com
> > https://www.redhat.com/mailman/listinfo/sclorg
> >
> 
> 
> --
> Petr Hracek
> email: phracek at redhat.com
> 
> _______________________________________________
> SCLorg mailing list
> SCLorg at redhat.com
> https://www.redhat.com/mailman/listinfo/sclorg
> 

-- 
Pavel Valena
Software Engineer, Red Hat
Brno, Czech Republic




More information about the SCLorg mailing list