AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 772932
Accepted
Itai Ganot
Itai Ganot
Asked: 2016-04-27 01:09:35 +0800 CST2016-04-27 01:09:35 +0800 CST 2016-04-27 01:09:35 +0800 CST

如何在 Ansible 剧本中创建一个本地事实,该事实将跳过以前运行中已经完成的步骤?

  • 772

我写了一本从 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

非常感谢您的帮助。

ansible ansible-playbook github
  • 1 1 个回答
  • 501 Views

1 个回答

  • Voted
  1. Best Answer
    Henrik Pingel
    2016-04-27T03:40:57+08:002016-04-27T03:40:57+08:00

    您可以使用stat 模块创建自定义检查和跳过

    你可能想做这样的事情:

    - name: Check if repository is checked out.
      stat: path={{ kafkacat_installdir }}/kafkacat
      register: git_dir
    
    - name: Git clone kafkacat
      git:  repo=git://github.com/company/kafkacat.git
            dest={{ kafkacat_installdir }} accept_hostkey=yes force=yes
      tags: kafkacat
      when: git_dir.stat is defined and git_dir.stat.isdir
    
    • 1

相关问题

  • 重复的 Ansible 任务

  • 无法形成站点中的文件的链接,该链接可用于使用 ansible 在远程服务器中启用的目录站点?

  • 如何执行 ansible 的特定角色?

  • Ansible 和 rbash

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve