WoJ
WoJ

Reputation: 29957

Why is this basic ansible playbook throwing an error?

I am trying to understand how ansible playbooks are structured and I am failing at a basic example:

---
- 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 error is:

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

I checked the consistency of the YAML file and the JSON output makes sense:

[
  {
    "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"
  }
]

I found out that the errors are often very much off the real bug (I had the same case as above, but it was an extra space after a = in a completely different place) - thus the whole playbook.

What is wrong with this playbook?

Upvotes: 0

Views: 479

Answers (2)

ocean
ocean

Reputation: 1350

As @Amit pointed out, it's not released yet.

Ansible seems to have a very zealous documentation release schedule, which sometimes outstrips the release of the actual supporting code :-)

Maybe try the service module instead for now, something like this should work:

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

Upvotes: 1

Amit
Amit

Reputation: 1006

The systemd module that you are attempting to use is present in Ansible 2.2 (which is not released as far as I know) and hence will not work with any of the currently available Ansible versions.

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

Upvotes: 1

Related Questions