YML错误IndentationError:预期ansible中的缩进块

时间:2016-06-02 05:23:00

标签: python ansible ansible-playbook

我收到了indentation错误:当我尝试运行ansiple playbook时,预计会出现缩进块。我已在https://yaml-online-parser.appspot.com/中进行验证。

类似的yml适用于其他服务器

工作

 ---

# Getting thename of the .txt file
- name: Getting name for anchor.txt 
  shell: "ls /mule/ansible/mule-enterprise-standalone-3.4.1/*.txt"
  register: the_file

- debug: msg="{{ the_file }}"

- set_fact: app_folder="{{ the_file.stdout | replace('-anchor.txt','') }}"

- debug: msg="{{ app_folder }}"

# Delete the .txt file
- name: Delete the anchor.txt file
  file: path="{{ the_file.stdout }}" state=absent 

# Wait until the app folder disappears
- name: Wait for the folder to 
  wait_for: path="{{ app_folder }}" state=absent

# Copy the zip file
- name: Copy the zip file 
  copy: src="../analytic-mule-services-mule-3.0.0-SNAPSHOT.zip" dest="/mule/ansible/mule-enterprise-standalone-3.4.1"

不工作

 ---

# Getting thename of the .txt file
- name: Getting name for anchor.txt file in 
  shell: "ls /app_2/ansible/mule-enterprise-standalone-3.4.1/*.txt"
  register: the_file

- debug: msg="{{ the_file }}"

- set_fact: app_folder="{{ the_file.stdout | replace('-anchor.txt','') }}"

- debug: msg="{{ app_folder }}"

# Delete the .txt file
- name: Delete the anchor.txt file in 
  file: path="{{ the_file.stdout }}" state=absent 

# Wait until the app folder disappears
- name: Wait for the folder to disappear
  wait_for: path="{{ app_folder }}" state=absent

# Copy the zip file
- name: Copy the zip file to 
  copy: src="../analytic-platform-service-3.0.0-SNAPSHOT.zip" dest="/app_2/ansible/mule-enterprise-standalone-3.4.1"

1 个答案:

答案 0 :(得分:0)

提示(可能是报告假象):非工作在初始---之前有一个空格(至少在问题中)

删除了非工作版本中前导空格的(统一)差异):

$ diff -u so_ansible_{not,''}working.yml 
--- so_ansible_notworking.yml   2016-06-02 11:18:09.000000000 +0200
+++ so_ansible_working.yml  2016-06-02 11:16:04.000000000 +0200
@@ -1,8 +1,8 @@
 ---

 # Getting thename of the .txt file
-- name: Getting name for anchor.txt file in 
-  shell: "ls /app_2/ansible/mule-enterprise-standalone-3.4.1/*.txt"
+- name: Getting name for anchor.txt 
+  shell: "ls /mule/ansible/mule-enterprise-standalone-3.4.1/*.txt"
   register: the_file

 - debug: msg="{{ the_file }}"
@@ -12,13 +12,13 @@
 - debug: msg="{{ app_folder }}"

 # Delete the .txt file
-- name: Delete the anchor.txt file in 
+- name: Delete the anchor.txt file
   file: path="{{ the_file.stdout }}" state=absent 

 # Wait until the app folder disappears
-- name: Wait for the folder to disappear
+- name: Wait for the folder to 
   wait_for: path="{{ app_folder }}" state=absent

 # Copy the zip file
-- name: Copy the zip file to 
-  copy: src="../analytic-platform-service-3.0.0-SNAPSHOT.zip" dest="/app_2/ansible/mule-enterprise-standalone-3.4.1"
\ No newline at end of file
+- name: Copy the zip file 
+  copy: src="../analytic-mule-services-mule-3.0.0-SNAPSHOT.zip" dest="/mule/ansible/mule-enterprise-standalone-3.4.1"
\ No newline at end of file

因此,如果内部没有外来字符(\r或标签混合了可能在副本中丢失的空格,粘贴并在SO处提交给服务器)那么我唯一注意到的就是上面的提示。请使用@ bent-blue建议的编辑器或我在评论中建议的hexdump / xxd / whatnot,以确保脚本能够收到您想要的内容。

从OP更新: 即使我得到同样的错误,我也修改了。 我一行一行,但都没有("意想不到的"白色空间也没有标签)

---
# Getting thename of the .txt file
- name: Getting name for anchor.txt file in host apsrd3277 and apsrd4450
  shell: "ls /mule/ansible/mule-enterprise-standalone-3.4.1/*.txt"
  register: the_file
- debug: msg="{{ the_file }}"
- set_fact: app_folder="{{ the_file.stdout|replace('-anchor.txt','') }}"
- debug: msg="{{ app_folder }}"
# Delete the .txt file
- name: Delete the anchor.txt file in apsrd3277 and apsrd4450
  file: path="{{ the_file.stdout }}" state=absent
# Wait until the app folder disappears
- name: Wait for the folder to disappear in apsrd3277 and apsrd4450
  wait_for: path = "{{ app_folder }}" state=absent
# Copy the zip file
- name: Copy the zip file to apsrd3277 and apsrd4450
  copy: src="../analytic-core-services-mule-3.0.0-SNAPSHOT.zip" dest="/mule/ansible/mule-enterprise-standalone-3.4.1"