2

I wrote an ansible playbook which is supposed to install a tool called kafkacat.

Most of the tasks in the playbook work, all but one (the most important one).

I'm compiling the tool from source and I've successfully installed it manually using the steps I'm building in ansible.

The relevant portion of the playbook is:

- name: Install kafkacat (configure)
    command: chdir={{ kafkacat_installdir }} {{ kafkacat_installdir }}/configure --enable-json --enable-static
    sudo: yes

  - name: Install kafkacat (make)
    command: chdir={{ kafkacat_installdir }} make
    environment:
      CPPFLAGS: ' -Itmp-bootstrap/usr/local/include'
      STATIC_LIB_yajl: ' tmp-bootstrap/usr/local/lib/libyajl_s.a'
      STATIC_LIB_rdkafka: ' tmp-bootstrap/usr/local/lib/librdkafka.a'
      LIBS: ' -lpthread -lrt '
    sudo: yes

  - name: Install kafkacat (make install)
    command: chdir={{ kafkacat_installdir }} make install
    sudo: yes

It is required for the "make" process to work, to know the exports I've specified in the task but for some reason it seems like the values are not exported properly and it causes the playbook to fail:

failed: [kafka-1] => {"changed": true, "cmd": ["make"], "delta": "0:00:00.422669", "end": "2016-04-25 15:10:16.085697", "rc": 2, "start": "2016-04-25 15:10:15.663028", "warnings": []}
stderr: /usr/bin/ld: cannot find -lyajl
/usr/bin/ld: cannot find -lyajl
collect2: error: ld returned 1 exit status
make: *** [kafkacat] Error 1
stdout: gcc -MD -MP  -Itmp-bootstrap/usr/local/include -g -O2 -Wall -Wfloat-equal -Wpointer-arith -g -O2 -Wall -Wfloat-equal -Wpointer-arith  -c kafkacat.c -o kafkacat.o
gcc -MD -MP  -Itmp-bootstrap/usr/local/include -g -O2 -Wall -Wfloat-equal -Wpointer-arith -g -O2 -Wall -Wfloat-equal -Wpointer-arith  -c format.c -o format.o
gcc -MD -MP  -Itmp-bootstrap/usr/local/include -g -O2 -Wall -Wfloat-equal -Wpointer-arith -g -O2 -Wall -Wfloat-equal -Wpointer-arith  -c json.c -o json.o

The reason why -lyajl is not found is because the export is not working.

I've also tried doing something like this:

  - name: Install kafkacat (configure)
    command: chdir={{ kafkacat_installdir }} CPFLAGS='CPPFLAGS= -Itmp-bootstrap/usr/local/include' STATIC_LIB_yajl='tmp-bootstrap/usr/local/lib/libyajl_s.a' STATIC_LIB_rdkafka='tmp-bootstrap/usr/local/lib/librdkafka.a' LIBS=' -lpthread -lrt' {{ kafkacat_installdir }}/configure --enable-json --enable-static

Your help is much appreciated and thanks in advance,

Ward - Trying Codidact
  • 12,899
  • 28
  • 46
  • 59
Itai Ganot
  • 10,644
  • 29
  • 93
  • 146
  • It looks like your STATIC_LIB_... values are prefixed by a space which will probably make the static lib check to fail. – Edenhill Apr 25 '16 at 22:39
  • Dude! I can't believe this damn space messed my whole playbook, thanks alot! please create an answer so I'll accept it. – Itai Ganot Apr 25 '16 at 22:55

2 Answers2

1

It looks like your STATIC_LIB_... values are prefixed by a space which will make the static lib check to fail.

Edenhill
  • 136
  • 2
0

Your env vars were not made available during the configure phase, so they were not used during the make. Take a look at the configure.base source for kafkacat.

From configure:

# Load base module
source mklove/modules/configure.base

From configure.base:

# Tries to figure out if we can use a static library or not.
# Arguments:
#  library name   (e.g. -lrdkafka)
#  compiler flags (optional "", e.g: "-lyajl")
# Returns/outputs:
#  New list of compiler flags
function mkl_lib_check_static {
    local libname=$1
    local libs=$2
    local arfile_var=STATIC_LIB_${libname#-l}

    # If STATIC_LIB_<libname_without_-l> specifies an existing .a file we
    # use that instead.
    if [[ -f ${!arfile_var} ]]; then
    libs=$(echo $libs | sed -e "s|$libname|${!arfile_var}|g")
    else
        libs=$(echo $libs | sed -e "s|$libname|${LDFLAGS_STATIC} $libname ${LDFLAGS_DYNAMIC}|g")
    fi

    echo $libs
}

In another situation you could have verified that ansible was setting the env properly by doing a quick debug

  - name: Show environment
    shell: "env"
    environment:
      CPPFLAGS: ' -Itmp-bootstrap/usr/local/include'
      STATIC_LIB_yajl: ' tmp-bootstrap/usr/local/lib/libyajl_s.a'
      STATIC_LIB_rdkafka: ' tmp-bootstrap/usr/local/lib/librdkafka.a'
      LIBS: ' -lpthread -lrt '
    sudo: yes
brent
  • 3,521
  • 3
  • 26
  • 37
  • I forgot to mention that I've also tried adding the env variables to the configure task as well but to no avail... – Itai Ganot Apr 25 '16 at 17:59