为什么这个基本的ansible剧本会抛出错误?

时间:2016-07-13 06:41:31

标签: yaml ansible ansible-playbook

我试图了解ansible playbooks的结构,我在一个基本的例子中失败了:

---
- hosts: all
  tasks:
    # update dependencies
    - name: install apt dependencies
      apt: name={{ item }}
      with_items:
        - python3-arrow
        - python3-netifaces
        - python3-requests
        - python3-docopt
    - name: install pip3 dependencies
      pip: name=scapy-python3 executable=pip3

    # install service
    - name: copy source file
      copy: src=honeysyn.py dst=/opt/sentinel-honeysyn/honeysyn.py
    - name: copy service file
      copy: src=honeysyn.service dst=/etc/systemd/system/honeysyn.service mode=0644
    - name: install service, restart and enable
      systemd:
        name: honeysyn
        daemon_reload: yes
        enabled: yes
        started: yes

错误是:

The offending line appears to be:

  copy: src=honeysyn.service dst=/etc/systemd/system/honeysyn.service mode=0644
- name: install service, restart and enable
  ^ here

YAML文件的I checked the consistency和JSON输出是有意义的:

[
  {
    "tasks": [
      {
        "name": "install apt dependencies", 
        "apt": "name={{ item }}", 
        "with_items": [
          "python3-arrow", 
          "python3-netifaces", 
          "python3-requests", 
          "python3-docopt"
        ]
      }, 
      {
        "pip": "name=scapy-python3 executable=pip3", 
        "name": "install pip3 dependencies"
      }, 
      {
        "copy": "src=honeysyn.py dst=/opt/sentinel-honeysyn/honeysyn.py", 
        "name": "copy source file"
      }, 
      {
        "copy": "src=honeysyn.service dst=/etc/systemd/system/honeysyn.service mode=0644", 
        "name": "copy service file"
      }, 
      {
        "systemd": {
          "started": true, 
          "enabled": true, 
          "name": "honeysyn", 
          "daemon_reload": true
        }, 
        "name": "install service, restart and enable"
      }
    ], 
    "hosts": "all"
  }
]

我发现错误往往远离真正的错误(我的情况与上面相同,但在一个完全不同的地方=之后是一个额外的空间) - 因此整个剧本

这个剧本有什么问题?

2 个答案:

答案 0 :(得分:1)

您尝试使用的systemd模块存在于Ansible 2.2中(据我所知尚未发布),因此不适用于任何当前可用的Ansible版本。

https://docs.ansible.com/ansible/systemd_module.html

答案 1 :(得分:1)

正如@Amit指出的那样,它尚未发布。

Ansible似乎有一个非常热心的文档发布时间表,有时会超过实际支持代码的发布: - )

也许现在尝试the service module,这样的事情应该有效:

- name: install service, enable and start
  service:
    name: honeysyn
    enabled: yes
    state: started