我尝试在同一个文件中插入2个ansible块,但Ansible用第二个块替换第一个块。
如果我插入接下来的两个街区:
- name: Setup java environment
blockinfile:
dest: /home/{{ user }}/.bashrc
block: |
#Java path#
JAVA_HOME={{ java_home }}/
- name: Setup hadoop environment
blockinfile:
dest: /home/{{ user }}/.bashrc
block: |
#Hadooppath#
HADOOP_HOME={{ hadoop_home }}/
只有第二个块会在文件中,因为它取代了第一个块。
答案 0 :(得分:2)
要在同一个文件中插入2个带Ansible的块,而不是用第二个块替换第一个块:
更改Ansible blockinfile标记:
blockinfile_task_1:
marker: "# {mark} ANSIBLE MANAGED BLOCK insertion 1"
blockinfile_task_2:
marker: "# {mark} ANSIBLE MANAGED BLOCK insertion 2"
对于前面的示例,剧本将是:
- name: Setup java environment
blockinfile:
dest: /home/{{ user }}/.bashrc
marker: "# {mark} ANSIBLE MANAGED BLOCK Java"
block: |
#Java path#
JAVA_HOME={{ java_home }}/
- name: Setup hadoop environment
blockinfile:
dest: /home/{{ user }}/.bashrc
marker: "# {mark} ANSIBLE MANAGED BLOCK Hadoop"
block: |
#Hadooppath#
HADOOP_HOME={{ hadoop_home }}/