通过完整的剧本出口环境价值的正确方法是什么?

我写了一本应该安装一个名为kafkacat的工具,

剧本中的大部分任务都是一样的(最重要的)。

我从源代码编译工具,我已经成功地安装它使用我build立在安全的步骤手动。

剧本的相关部分是:

- 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 

“make”过程需要工作,要知道我在任务中指定的出口,但由于某些原因,这些值似乎不能正确导出,导致操作手册失败:

 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 

没有find-lyajl的原因是因为输出不起作用。

我也试着做这样的事情:

  - 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 

您的帮助是非常感谢和提前感谢,

它看起来像你的STATIC_LIB _…值前缀的空间将使静态lib检查失败。

你的环境variables在configure阶段不可用,所以在make过程中不使用它们。 看看kafkacat的configure.base源代码。

configure

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

configure.base

 # Tries to figure out if we can use a static library or not. # Arguments: # library name (eg -lrdkafka) # compiler flags (optional "", eg: "-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 } 

在另一种情况下,你可以证实,通过快速debugging,正确设置env是可行的

  - 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