Asier Gomez
Asier Gomez

Reputation: 6588

Ansible blockinfile error

I am trying to use blockinfile, so I am doing some test. I have the next task, but it give me a sintax error.

- name: Prueba
  blockinfile:
  dest: /opt/a
  block: | pruebaa
    pruebaaa

This is the error that I have:

 ERROR! Syntax Error while loading YAML.


The error appears to have been in '/home/ikerlan/ansiblePlaybooks/hadoop-Ansible/roles/comun/tasks/main.yml': line 39, column 12, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

  dest: /opt/a
  block: | pruebaa
           ^ here

My complete main.yml is the next

#NAMENODES

#Los siguientes comandos solo se ejecutaran en los namenodes

- name: Archivo de configuracion zoo.cfg
  template: src=zoo.cfg.j2 dest=/opt/zookeeper-3.4.7/conf/zoo.cfg

- name: Prueba
      blockinfile:
      dest: /opt/a
      block: | pruebaa
        pruebaaa

- name: Crear carpeta ZooData
  file: path=/opt/ZooData state=directory mode=0755
  #command: mkdir -p /opt/ZooData/ creates=/opt/ZooData/

- name: Permisos ZooData
  command: chown vagrant /opt/ZooData/

- name: Crear carpeta name
  file: path=/hdfs/name state=directory mode=0755
  #command: mkdir -p /hdfs/name/ creates=/hdfs/name/

- name: Permisos hdfs/name
  command: chown vagrant /hdfs/name/

- name: Crear carpeta journalnode
  file: path=/hdfs/journalnode state=directory mode=0755
  #command: mkdir -p /hdfs/journalnode/ creates=/hdfs/journalnode/

- name: Permisos hdfs/journalnode
  command: chown vagrant /hdfs/journalnode/

- name: Archivo de configuracion slaves
  template: src=slaves.j2 dest=/opt/hadoop-2.7.1/etc/hadoop/slaves

Any help would be great. Thanks

Upvotes: 1

Views: 1218

Answers (2)

helloV
helloV

Reputation: 52443

I do not have ansible 2.0 to test this. You cannot have any char after block: | Try this:

  blockinfile:
  dest: /opt/a
  block: |
    pruebaa
    pruebaaa

Upvotes: 1

tlo
tlo

Reputation: 1631

I guess there should be a newline after the | character. Also a playbook (or a YAML file in general) must start with ---.

Upvotes: 0

Related Questions