[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

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:

- 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 cines fr
IM: sviscapi (Skype)

----- Mail original -----
De: "Petr Hracek" <phracek redhat com>
À: "viscapi" <viscapi cines fr>
Cc: "sclorg" <sclorg redhat com>, "caux" <caux 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 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 cines fr
> IM: sviscapi (Skype)
>
> _______________________________________________
> SCLorg mailing list
> SCLorg redhat com
> https://www.redhat.com/mailman/listinfo/sclorg
>


-- 
Petr Hracek
email: phracek redhat com


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]