Ansible 收集事实不起作用?

Ansible 收集事实不起作用?

每次我运行剧本时,ansible 都会一次又一次地安装软件包,即使它已经安装了,那么它实际上是如何工作的呢?

ansible-playbook -i hosts  site.yml
GATHERING FACTS *************************************************************** 
ok: [192.168.0.2]

TASK: [Install via apt] *************************************** 
changed: [192.168.0.2] => (item=build-essential,python-dev,python-software-properties,python-setuptools)

我的食谱(任务):

 name: Install via apt
  action: apt pkg=$item
  with_items:
    - build-essential
    - python-dev
    - python-software-properties

答案1

我无法使用此剧本重现您的错误:

- hosts: 10.0.0.2
  sudo: yes

  tasks:

    - name: Install via apt
      action: apt pkg=$item
      with_items:
         - build-essential
         - python-dev
         - python-software-properties

正如预期的那样,剧本的连续执行是幂等

$ ansible-playbook pkg.playbook -K
sudo password:

PLAY [10.0.0.2] *********************

GATHERING FACTS *********************
ok: [10.0.0.2]

TASK: [Install via apt] *********************
ok: [10.0.0.2] => (item=build-essential,python-dev,python-software-properties)

PLAY RECAP *********************
10.0.0.2                       : ok=2    changed=0    unreachable=0    failed=0

相关内容