2017-04-07 72 views
-3
--- 
- 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 

錯誤使用處理器,同時運行的打法是:錯誤而Ansible

爲YAML
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 

回答

0

大部分的語法錯誤是因爲不正確的縮進,因爲YAML依賴於空白。

請參閱從playbook documentation這個例子:

--- 
- hosts: webservers 
    vars: 
    http_port: 80 
    max_clients: 200 
    remote_user: root 
    tasks: 
    - name: ensure apache is at the latest version 
    yum: name=httpd state=latest 
    - name: write the apache config file 
    template: src=/srv/httpd.j2 dest=/etc/httpd.conf 
    notify: 
    - restart apache 
    - name: ensure apache is running (and enable it at boot) 
    service: name=httpd state=started enabled=yes 
    handlers: 
    - name: restart apache 
     service: name=httpd state=restarted 

注意如何tasks縮進到同一級別hostsvarsremote_user

另請參閱tasks數組中的項目如何將短劃線(-)縮進與單詞「tasks」相同的級別。

此縮進非常重要,因爲這就是Yaml如何確定哪些元素屬於其他元素。如果你沒有正確縮進,它就不知道如何解析它。

所以這應該爲你工作

--- 
- 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 
+0

謝謝。你能幫我優化我上面提到的腳本嗎? – Gladiator

+0

看我的編輯。你所要做的就是在幾行開始時刪除幾個額外的空格。 –

+0

劇本效果很好。現在我需要用相同的條件語句添加kernel.shmmax值,它會在這些條件下對多個條目使用sysctl文件嗎? @ Yep_It's_Me – Gladiator