How to add multiple lines in a file using Ansible playbook

0 votes

Hi Guys,

I am trying to add multiple lines in a file using the Ansible playbook. When the task will run it will automatically update the lines in that file. How can I do that?

Sep 16, 2020 in Ansible by akhtar
• 38,210 points
5,264 views

1 answer to this question.

0 votes

Hi@akhtar,

You can update your file using lineinfile module. This module can update the line in a file. But if you want to update multiple lines you need to use the item keyword in your code as shown below.

- name: Update hosts
  lineinfile:
    path: /etc/hosts
    state: present
    line: "{{ item }}"
  with_items:
  - '192.168.0.108 K8_slave'
  - '192.168.0.105 K8_master'
answered Sep 16, 2020 by MD
• 95,300 points

Related Questions In Ansible

0 votes
1 answer

How do I wget a file from web server using shell in the ansible playbook

Hey Ayaan, you could probably use this ...READ MORE

answered Jan 24, 2019 in Ansible by Anushri
2,492 views
0 votes
1 answer

How to create a security group in AWS using Ansible-Playbook?

Hi@akhtar, You can use the ec2_group module in ...READ MORE

answered Aug 13, 2020 in Ansible by MD
• 95,300 points
1,189 views
0 votes
2 answers

How to create a directory in remote nodes using Ansible-Playbook?

You can read install and setup apache ...READ MORE

answered Aug 23, 2020 in Ansible by anonymous
• 160 points
851 views
0 votes
1 answer

How to mount a dvd in a folder using Ansible playbook?

Hi@akhtar, Ansible has the mount module that is idempotent ...READ MORE

answered Sep 16, 2020 in Ansible by MD
• 95,300 points
284 views
+15 votes
2 answers

Git management technique when there are multiple customers and need multiple customization?

Consider this - In 'extended' Git-Flow, (Git-Multi-Flow, ...READ MORE

answered Mar 26, 2018 in DevOps & Agile by DragonLord999
• 8,450 points
1,247 views
+2 votes
1 answer
0 votes
1 answer

How to overwrite the content of a file in remote systems using Ansible playbook?

Hi@akhtar, You can find one argument in the ...READ MORE

answered Aug 2, 2020 in Ansible by MD
• 95,300 points
4,453 views
0 votes
1 answer

How to add several lines in a file using lineinfile module?

Hi@akhtar, When we need to perform a task ...READ MORE

answered Sep 2, 2020 in Ansible by MD
• 95,300 points
171 views