我想從一本完美的劇本中設置(並堅持)一個環境變量。我寫道:在Ansible上設置環境變量
# Set the JVM ram
- name: Set the JVM ram
environment:
ES_HEAP_SIZE: 2g
不過,我得到:
ERROR: 'action' or 'local_action' attribute missing in task "Set the JVM ram"
我想從一本完美的劇本中設置(並堅持)一個環境變量。我寫道:在Ansible上設置環境變量
# Set the JVM ram
- name: Set the JVM ram
environment:
ES_HEAP_SIZE: 2g
不過,我得到:
ERROR: 'action' or 'local_action' attribute missing in task "Set the JVM ram"
的environment
標籤是不是工作,而是可以應用到各個任務或全局應用的屬性。每你想要做你的劇本上只是指定這樣的東西是什麼ansible FAQ:
---
environment:
ES_HEAP_SIZE: 2g
注意,這是從你指定什麼不同,因爲- name
指定單個任務的開始,這裏的例子上面只是在頂層定義了一個字典,它可以在處理任務之前作爲環境變量進行解釋和應用。
你有正確的想法。但是你錯過了你的「行動」;每個任務都需要一個。您的environment
設置將適用於您(但僅限於此任務):
# Set the JVM ram
- name: Set the JVM ram
command: ./bin/elasticsearch # now using envvar instead of -Xmx10g -Xms10g
environment:
ES_HEAP_SIZE: 2g
# OR
#environment: {ES_HEAP_SIZE: 2g}
elasticsearch被定義爲系統服務。我不能像那樣啓動它。 – poiuytrez
這很好。我只是把它作爲示例命令。你必須有一些東西可以運行。或者,您可以將任務設置爲'lineinfile',將其放入rc/environment文件中。 –