Saturday, June 5, 2021

Ansible playbook to add a line in a file

Ansible playbook to add a line in a file

---
  - hosts: node1
    tasks:
    - name: create file
      file:
        path: /home/ansible/hostname.conf
        state: touch
    - name:
      lineinfile:
        dest: /home/ansible/hostname.conf
        line: Hostname={{ ansible_hostname }}
        state: present

No comments: