Ansible如何在已经运行时跳过./configure并进行安装

时间:2018-08-17 15:32:28

标签: ansible

我的剧本下面有摘录。它可以正确安装软件,但是当我重新运行剧本时,将再次运行“配置”和“进行安装”步骤。播放摘要显示2个更改。脚本完成后,计算机的状态是正确的,但是我不希望重新运行这些步骤。如何跳过已执行的步骤?

- name: Install smalt
  block:
    # Download and uncompress smalt
    - unarchive:
        src="https://sourceforge.net/projects/smalt/files/smalt-0.7.6-static.tar.gz"
        dest="{{ansible_user_dir}}/software"
        creates="{{ansible_user_dir}}/software/smalt-0.7.6"
        copy=no
    - name: configure
      command: ./configure
      args:
        chdir: "{{ansible_user_dir}}/software/smalt-0.7.6"
    - make:
        chdir: "{{ansible_user_dir}}/software/smalt-0.7.6"
    - make:
        chdir: "{{ansible_user_dir}}/software/smalt-0.7.6"
        target: install
      become: yes

1 个答案:

答案 0 :(得分:1)

  

如何跳过已运行的步骤?

通过在评估该块之前测试实际的期望状态,然后使用when子句保护该块;例如:

- name: check for smalt installation
  stat:
    path: /usr/local/bin/smalt  # <-- or whatever
  register: smalt_bin

- name: Install smalt
  when: not smalt_bin.stat.exists
  block:
    - unarchive: # etc etc