【问题标题】:Error in yaml code could not find expected ':'yaml 代码中的错误找不到预期的“:”
【发布时间】:2021-10-08 03:00:46
【问题描述】:

yaml 代码

- hosts: all

  tasks:
  #Import Remi GPG key - see: http://rpms.famillecollet.com/RPM-GPG-KEY-remi
  wget http://rpms.famillecollet.com/RPM-GPG-KEY-remi \ -O /etc/pki/rpm-gpg/RPM-GPG-KEY-remi
  rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-remi
 #Install Remi repo
  rpm -Uvh --quiet \
    http://rpms.famillecollet.com/enterprise/remi-release-6.rpm

安装 EPEL 存储库。

yum install epel-release

安装 Node.js(npm 及其所有依赖项)。

yum --enablerepo=epel install node

编译时出现以下错误:ERROR! Syntax Error while loading YAML.

错误似乎出现在“/home/shahzad/playbook.yml”中:行 7,第 3 列,但可能在文件中的其他位置,具体取决于确切的 语法问题。

违规行似乎是:

  wget http://rpms.famillecollet.com/RPM-GPG-KEY-remi \ -O /etc/pki/rpm-gpg/RPM-GPG-KEY-remi
  rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-remi
  ^ here
exception type: <class 'yaml.scanner.ScannerError'>
exception: while scanning a simple key
  in "<unicode string>", line 6, column 3
could not find expected ':'
  in "<unicode string>", line 7, column 3

【问题讨论】:

  • 能否请您发布您的 yaml 代码?这似乎不是正确的 yaml 代码。

标签: ansible


【解决方案1】:

我按照上述说明安装了所有内容,但我使用安装程序 alien 在 Ubuntu 18.04 上转换和安装 rpm packages。 但是您将无法使用 yum 进行安装,因为某些软件包不在其列表中。

使用外星人:

 # apt install alien # apt install -y

 # cd /tmp

 # wget http://rpms.famillecollet.com/RPM-GPG-KEY-remi \ -O /etc/pki/rpm-gpg/RPM-GPG-KEY-remi

 # wget http://rpms.famillecollet.com/enterprise/remi-release-6.rpm

 # alien -kiv remi-release-6.rpm

 # ls -l

 # wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm

 # alien epel-release-latest-8.noarch.rpm

 # ls -l

 # alien -k epel-release-latest-8.noarch.rpm ; alien -i epel-release-latest-8.noarch.rpm

 # cd /home/user

 # apt install curl gcc g++ make # apt install -y

 # curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash -

 # apt install nodejs # apt install -y

 # curl -sL https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -

 # echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list

 # apt update ; sudo apt install yarn # apt install -y

 # apt install nodejs ; apt upgrade ; passwd -dl root ; reboot # apt install -y

但是我仍然有同样的错误Invalid YAML: could not find expected ':':,但是在命令networkctl 上它对我来说变得更好了,它说failed(尽管在安装 node.js、remi-release、epel-release 之前它没有'不要那样签名)哪些接口配置不正确。

 IDX LINK             TYPE               OPERATIONAL SETUP     
   1 lo               loopback           carrier     unmanaged

   2 ens11            ether              off         unmanaged

   3 enp2t1           ether              routable    configured

   4 br0              ether              off         failed

   5 vlan5            ether              off         configuring

这些安装包让你深入了解界面错误,这个方法有效!!!!!!!!! Shahzad Adil 谢赫谢谢你!

【讨论】:

    【解决方案2】:

    我在 yaml 中使用 PowerShell 任务运行命令时遇到了同样的错误。

    - task: PowerShell@1
      inputs:
        scriptType: inlineScript
        inlineScript: |
          Command1
          Commands2  
    

    我通过缩进命令/脚本块来修复此错误。
    您需要在inlineScript: | 下缩进Command1 一个杠杆。

    【讨论】:

      【解决方案3】:
      • 如果您希望在 yaml 剧本中使用 shell 命令,例如 wget,则需要使用 shell 模块:
      - name: Import Remi GPG key
        shell: wget ...
      
      • “:”是yaml中的特殊字符,请阅读ansible官方文档中的YAML Syntax page,以便引用。

      • yum命令可以使用ansible的yum模块。

      作为最佳实践,您可以使用 http://www.yamllint.com/ 来调试 YAML 语法,检查解析器失败的确切行和列。

      【讨论】:

        猜你喜欢
        • 2017-03-17
        • 2021-03-12
        • 2014-02-04
        • 2021-12-08
        • 2019-01-10
        • 2021-02-04
        • 2017-01-24
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多