YML错误:缩进错误,预期为缩进块在Ansible中。

2024-04-23 12:10:17 发布

您现在位置:Python中文网/ 问答频道 /正文

我得到了缩进错误:当我试图运行ansiple剧本时需要一个缩进的块。我在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"

不起作用

^{pr2}$

Tags: thenamedebugtxtappforansiblefolder
1条回答
网友
1楼 · 发布于 2024-04-23 12:10:17

提示(可能报告人工制品):非工作的在初始^{之前有一个空格(至少在问题中)

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

$ 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或hextump/xxd/whatnot我在评论中建议的编辑器,以确保脚本收到您想要的。在

从操作更新: 即使我有同样的错误,我也修改了。 我一行一行地浏览,但都没有(“意想不到的”空白或制表符)

^{pr2}$

相关问题 更多 >