Playbook的运行次数比提供的库存多

时间:2017-09-13 13:31:43

标签: ansible ansible-2.x

我的剧本,即使我的库存中只有一台服务器,也会运行两次。

[me@server ansible_scripts]$ sudo -u userA ansible-playbook ssl_playbook.yml -i inventories/staging ssl_playbook.yml --private-key=/path/to/key.key --u userB

PLAY [custom_group] ***********************************************************

TASK [Copy and backup SSL related files] ***************************************
ok: [server.mydomain.com] => (item=ssl_chain.crt)
ok: [server.mydomain.com] => (item=ssl.crt)
ok: [server.mydomain.com] => (item=ssl.key)

PLAY RECAP *********************************************************************
server.mydomain.com : ok=2    changed=0    unreachable=0    failed=0

PLAY [custom_group] ***********************************************************

TASK [Copy and backup SSL related files] ***************************************
ok: [server.mydomain.com] => (item=ssl_chain.crt)
ok: [server.mydomain.com] => (item=ssl.crt)
ok: [server.mydomain.com] => (item=ssl.key)

PLAY RECAP *********************************************************************
server.mydomain.com : ok=4    changed=0    unreachable=0    failed=0

inventories/staging/hosts

[custom_group]
server.mydomain.com

ssl-playbook.yml

- hosts: custom_group
  gather_facts: false
  tasks:
  - name: Copy and backup SSL related files
    copy: 
      src: /u01/sslcert/{{item}}
      dest: /u01/etc/httpd/{{item}}
      backup: true
      force: true
      mode: "u=rwx,g=,o="
    with_items: '{{ssl_certificate_files}}'
    become: true
    become_user: apache

  handlers:
  - name: restart apache
    service: name=httpd state

inventories/staging/group_vars

ssl_certificate_files:
  - ssl_chain.crt
  - ssl.crt
  - ssl.key

1 个答案:

答案 0 :(得分:4)

从命令中删除重复的条目ssl_playbook.yml