在我的本地主机中下载 apache http 的 Ansible YAML playbook 中出现语法错误

在我的本地主机中下载 apache http 的 Ansible YAML playbook 中出现语法错误
---
- hosts: test_server
  remote_user: root
  tasks:
    - name: extract tar file
      command: tar -xvzf httpd-2.4.41.tar.gz 
    - name: go to the extracted directory
      command: cd httpd-2.4.41
    - name: Run below commands
      command:
         - ./configure --prefix=instance --with-mpm=worker --enable-proxy -enable-deflate --enable-proxy-balancer --enable-rewrite --enable-apr -enable-apr-util --enable-ssl --enable-setenvif --with-ssl=/usr/local/ssl 
         - make
         - make install
     - name: change directory
       command: cd
     - name: check version
       command: /app/apache/instance/bin/apachectl -v
     - name: start httpd
       command: /app/apache/instance/bin/apachectl start  

但我遇到了以下错误

[root@91c2ebbd3d57 ~]# ansible-playbook test.yml
ERROR! Syntax Error while loading YAML.
  did not find expected '-' indicator

该错误似乎位于“/root/test.yml”:第 14 行第 6 列中,但可能位于文件中的其他位置,具体取决于确切的语法问题。

有问题的行似乎是:

     - make install
 - name: change directory
 ^ here

答案1

试试这个

---
- hosts: test_server
  remote_user: root
  tasks:

  - name: extract tar file
    command: tar -xvzf httpd-2.4.41.tar.gz 

  - name: Run below commands
    shell: |
      ./configure \
      --prefix=instance \
      --with-mpm=worker \
      --enable-proxy \
      --enable-deflate \
      --enable-proxy-balancer \
      --enable-rewrite \
      --enable-apr \
      --enable-apr-util \
      --enable-ssl \
      --enable-setenvif \
      --with-ssl=/usr/local/ssl 
      make
      make install
    args:
      chdir: /root/httpd-2.4.41

  - name: check version
    command: /app/apache/instance/bin/apachectl -v

  - name: start httpd
    command: /app/apache/instance/bin/apachectl start`

答案2

问题(语法错误)是该- name: change directory行以及该行之后的所有行的缩进。它们都缩进了一个空格太多。

相关内容