首页 文章

Ansible寄存器和.changed无效

提问于
浏览
0

我有一个安装包的playbook,如果安装了包,则需要运行命令 . 我使用了 register <variable><variable>.changed 这样做,但是,这并没有做错 . 这是我的代码 .

- name: install syncthing (arch)
  pacman: name=syncthing state=latest
  when: ansible_distribution in ['Archlinux', 'Manjaro Linux']
  register: syncthing

- name: enable syncthing
  command: systemctl enable syncthing@jay.service
  when: syncthing.changed

会发生什么是第一个块安装syncthing包,并给我以下输出:

改变了:[myhost]

然后下一个块应该执行,因为上一步注册了一个更改,但不幸的是,它没有:

跳过:[10.10.99.193]

我是一个简单的解决方案,我似乎正在从我阅读的文档中正确地做到这一点,以及以下帖子:https://raymii.org/s/tutorials/Ansible_-_Only-do-something-if-another-action-changed.html

1 回答

  • 0
    - name: install syncthing (arch)
      pacman: name=syncthing state=latest
      when: ansible_distribution in ['Archlinux', 'Manjaro Linux']
      register: syncthing
    
    - name: enable syncthing
      command: systemctl enable syncthing@jay.service
      when: ansible_distribution in ['Archlinux', 'Manjaro Linux'] and syncthing is defined and syncthing.changed
    

相关问题