I try to insert 2 ansible blocks in the same file, but Ansible replace the first block with the second.
If I insert the next 2 blocks:
- 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 }}/
Only the second block will be in the file, becouse it replace the first.
To insert 2 blocks with Ansible in the same file and don't replace the first with the second:
Change the Ansible blockinfile marker:
blockinfile_task_1:
marker: "# {mark} ANSIBLE MANAGED BLOCK insertion 1"
blockinfile_task_2:
marker: "# {mark} ANSIBLE MANAGED BLOCK insertion 2"
For the previous example, the playbook will be:
- 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 }}/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With