我写了一本从 git 三个 repo 克隆并从源代码编译它们的剧本。
每当我配置使用此剧本的机器时,都会克隆存储库,无论存储库的本地副本是否已更新。
我希望 git clone 仅在第一次发生,其余时间在我运行剧本时,我希望 Ansible 跳过这一步。
我已经阅读了 Ansible 文档上的“本地事实”,但我很难理解它应该如何实现。
这是我写的剧本:
---
- name: Install required packages
apt: name={{item}} state=installed
with_items:
- "librdkafka-dev"
- "libyajl-dev"
- "librdkafka1"
- "cmake"
sudo: yes
tags: kafkacat
- name: Git clone kafkacat
git: repo=git://github.com/company/kafkacat.git
dest={{ kafkacat_installdir }} accept_hostkey=yes force=yes
tags: kafkacat
- name: Git clone librdkafka
git: repo=git://github.com/company/librdkafka.git
dest={{ kafkacat_installdir }}/librdkafka force=yes version={{ librdkafka_git_version }}
tags: kafkacat
- name: Git clone yajl
git: repo=git://github.com/company/yajl
dest={{ kafkacat_installdir }}/yajl force=yes version={{ yajl_git_version }}
tags: kafkacat
- name: librdkafka compilation (configure)
command: chdir={{ kafkacat_installdir }}/librdkafka {{ kafkacat_installdir }}/librdkafka/configure
tags: kafkacat
- name: librdkafka compilation (make)
command: chdir={{ kafkacat_installdir }}/librdkafka make
tags: kafkacat
- name: librdkafka compilation (make install)
command: chdir={{ kafkacat_installdir }}/librdkafka make DESTDIR={{ kafkacat_installdir }}/tmp-bootstrap install
tags: kafkacat
- name: yajl compilation (configure)
command: chdir={{ kafkacat_installdir }}/yajl {{ kafkacat_installdir }}/yajl/configure
tags: kafkacat
- name: yajl compilation (make)
command: chdir={{ kafkacat_installdir }}/yajl make
tags: kafkacat
- name: yajl compilation (make install)
command: chdir={{ kafkacat_installdir }}/yajl make DESTDIR={{ kafkacat_installdir }}/tmp-bootstrap install
tags: kafkacat
- name: Set vagrant user & group as the owner of the folder
file: path={{ kafkacat_installdir }} owner={{ kafkacat_owner }} group={{ kafkacat_group }} state=directory recurse=yes
sudo: yes
tags: kafkacat
- name: kafkacat compilation (configure)
command: chdir={{ kafkacat_installdir }} {{ kafkacat_installdir }}/configure --enable-json --enable-static
environment: env
tags: kafkacat
#- debug: var=env
- name: kafkacat compilation (make)
command: chdir={{ kafkacat_installdir }} make
environment: env
tags: kafkacat
#- debug: var=env
- name: kafkacat compilation (make install)
command: chdir={{ kafkacat_installdir }} make install
sudo: yes
tags: kafkacat
非常感谢您的帮助。
您可以使用stat 模块创建自定义检查和跳过
你可能想做这样的事情: