Linux 在Ansible中使用处理程序时出错

Linux 在Ansible中使用处理程序时出错,linux,unix,ansible,redhat,devops,Linux,Unix,Ansible,Redhat,Devops,Yaml的大多数语法错误都是因为缩进不正确,因为Yaml依赖于空格 请参见下面的示例: --- -主机:Web服务器 变量: http_端口:80 最大客户数:200 远程用户:root 任务: -名称:确保apache是最新版本 yum:name=httpd state=latest -名称:编写apache配置文件 模板:src=/srv/httpd.j2 dest=/etc/httpd.conf 通知: -重新启动apache -名称:确保apache正在运行(并在启动时启用) 服务:na

Yaml的大多数语法错误都是因为缩进不正确,因为Yaml依赖于空格

请参见下面的示例:

---
-主机:Web服务器
变量:
http_端口:80
最大客户数:200
远程用户:root
任务:
-名称:确保apache是最新版本
yum:name=httpd state=latest
-名称:编写apache配置文件
模板:src=/srv/httpd.j2 dest=/etc/httpd.conf
通知:
-重新启动apache
-名称:确保apache正在运行(并在启动时启用)
服务:name=httpd state=started enabled=yes
处理程序:
-名称:重启apache
服务:名称=httpd状态=重新启动
注意
任务
是如何缩进到与
主机
变量
远程用户
相同的级别的

另请参见
任务
数组中的项目如何将破折号(
-
)缩进到与单词“tasks”相同的级别

这个缩进很重要,因为这是Yaml确定哪些元素属于其他元素的方式。如果没有正确缩进所有内容,它就不知道如何解析它

所以这应该对你有用

---
-名称:Oracle DB Prereqs
主持人:沙盒
变成:真的
收集事实:是的
变量:
上海:16384
施马卢中部:32768
上海:65536
上海市郊:262144
任务:
-名称:为小于16G的内存大小设置的最小值

时间:ansible{shmall}和ansible{shmall}和ansible{shmall}和ansible{shmall}和ansible{shmall}和ansible{shmall}和ansible{memtotal}谢谢。你能帮我优化上面提到的脚本吗?请看我的编辑。你所要做的就是在几行的开头删除几个额外的空格。脚本运行良好。现在,我需要使用相同的条件语句添加kernel.shmmax值。在这些条件下,它是否可以处理sysctl文件中的多个条目@是的,我不知道这是什么。我以前没有用sysctl文件做过任何工作。只要给它一个镜头,如果它给你一个错误,那么就在上面搜索:)
---
- name: Oracle DB Prereqs
  hosts: sandbox
  become: true
  gather_facts: yes
  vars:
      shmall_ent: 16384
      shmall_mid: 32768
      shmall_lar: 65536
      shmall_exlar: 262144

   tasks:
    - name: SHMALL value to set for memory size less than 16G
      when: ansible_memtotal_mb <= {{ shmall_ent }}
      notify:
        - SHMALL ent

    - name: SHMALL value to set for memory size between 16G and 32G
      when: (ansible_memtotal_mb > {{ shmall_ent }} and ansible_memtotal_mb <= {{ shmall_mid }})|int
      notify:
        - SHMALL mid

    - name: SHMALL value to set for memory size between 32G and 64G
      when: (ansible_memtotal_mb > {{ shmall_mid }} and ansible_memtotal_mb <= {{ shmall_lar }})|int
      notify:
        - SHMALL lar

    - name: SHMALL value to set for memory size between 64G and 256G
      when: (ansible_memtotal_mb > {{ shmall_lar }} and ansible_memtotal_mb <= {{ shmall_exlar }})|int
      notify:
        - SHMALL exlar
      handlers:
    - name: SHMALL ent
      sysctl:
        name: kernel.shmall
        value: 3670016
        sysctl_file: /etc/sysctl.d/99-sysctl.conf
    - name: SHMALL mid
      sysctl:
       name: kernel.shmall
       value: 7340032
       sysctl_file: /etc/sysctl.d/99-sysctl.conf
    - name: SHMALL lar
      sysctl:
       name: kernel.shmall
       value: 14680064
       sysctl_file: /etc/sysctl.d/99-sysctl.conf
    - name: SHMALL exlar
      sysctl:
       name: kernel.shmall
       value: 57671680
       sysctl_file: /etc/sysctl.d/99-sysctl.conf
ERROR! Syntax Error while loading YAML.


The error appears to have been in '/home/rjoy/ansible/roles/oracle/playbook/oraunix.yml': line 12, column 4, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:


   tasks:
   ^ here