scl enable rh-mariadb102 bash doesn't work with Ansible playbook

4.3k Views Asked by At

I'm new to stackoverflow... It seems to be a pretty good place to share knowledge and to find solution with a very interesting community.

I've a problem with Ansble and the "scl" "mysql_install_dir" commands.

When I execute manually "scl enable rh-mariadb102 bash && mysql_install_dir ..." it's perfectly working when I do it right in the server's console.

But when I try to build a task on Ansible :

- name: "Execute mysql_install_db to prepare DB"
  shell: |
    scl enable rh-mariadb102 bash
    mysql_install_db --datadir=/data/{{ item.instance_name }}/db/mariadb102
  become_user: root
  with_items: "{{ vars_list }}"

It return error :

"Use \"scl enable rh-mariadb102 'service ...'\" invocation"

This seems like Ansible doesn't execute well the scl enable command... or something like this.

Someone have been stuck before with this issue ?

Thanks for the help and sorry for bad english.

1

There are 1 best solutions below

1
On

The scl command opens a subshell and cloes it again. Something like this should work:

- name: "Execute mysql_install_db to prepare DB"
  shell: |
    scl enable rh-mariadb102 -- mysql_install_db --datadir=/data/{{ item.instance_name }}/db/mariadb102
  become_user: root
  with_items: "{{ vars_list }}"

That is, run the actual command under scl enable.