I have an ansible playbook which raises an error (with a dreadful message, as usual):
ERROR! unexpected parameter type in action: <class 'ansible.parsing.yaml.objects.AnsibleSequence'>
The error appears to have been in '/root/myplaybook.yml': line 17, column 7, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
# configure rsyslog
- name: configure rsyslog to expose events on port 42000
^ here
The line in question is typical of other lines I have in this and other playbooks:
# prepare environment
# configure rsyslog
- name: configure rsyslog to expose events on port 42000
lineinfile:
- create: yes
- dest: /etc/rsyslog.d/expose-42000.conf
- line: "*.* @127.0.0.1:42000"
notify:
- restart rsyslog
The file is validated by three online checkers, so there are no YAML errors. Is this fact enough for the file to be a correct ansible playbook?
What I am trying to understand is whether a correct YAML file leaves me only with ansible syntax errors (a module which does not exist for instance) or is a playbook an extension of YAML (in the sense that a line like - name: blah blah blah
is OK from a YAMl perspective, but will be rejected by ansible because (I am making up an example) it has more than two words.
In other words I am checking if the following can be true: the YAML syntax is OK, the ansible keywords are OK but ansible does not conform to YAML syntax fully by having some limitations.
EDIT: I had an error, spotted by Konstantin in his answer. I will leave this question in place since it helped me to understand that ansible does not put constraints on the YAML file itself, so when there is an error and the validation goes though I am really left with specific ansible syntax errors (or logical, like in my case).
Automation with Ansible PlaybooksAnsible uses YAML syntax for expressing Ansible playbooks. This chapter provides an overview of YAML. Ansible uses YAML because it is very easy for humans to understand, read and write when compared to other data formats like XML and JSON.
yaml as file extension. Different documents in YAML can be separated using three dashes ( --- ). You use three dots ( ... ) to mark the end of a document without starting a new one. A document in block style uses spaces to structure the document.
Ansible playbooks use YAML lists to represent a list of items. You can express them in two ways, shown below. Each element in the list is represented in YAML as a new line with the same indentation, starting with - followed by a space.
No, valid YAML does not necessarily give you a valid Ansible playbook.
The error message is unexpected parameter type in action
.
So Ansible can't interpret what you want. Specifically:
lineinfile:
- create: yes
- dest: /etc/rsyslog.d/expose-42000.conf
- line: "*.* @127.0.0.1:42000"
create
, dest
and line
are parameters of lineinfile
action, but you try to feed a list of three dicts into the lineinfile, because you prepend each parameter with a dash. This is correct from the YAML syntax perspective, but Ansible can't parse it because you are not supposed to feed lists into actions.
To correct the error, remove dashes before these parameters.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With