Parsing and Comparing a text file

41 views
Skip to first unread message

Mona Gopal

unread,
Feb 8, 2017, 1:01:03 AM2/8/17
to Ansible Project
Hello,

My requirement is as below:

A text file with configuration contents would be given to us by the product teams.
I will have to compare this file against the one on the remote host , find out the difference, and replace values for the variables where it doesn't match.
How is this achievable using Ansible.
Kindly suggest a solution.


Thanks in advance,
Mona G

Johannes Kastl

unread,
Feb 8, 2017, 3:44:22 AM2/8/17
to ansible...@googlegroups.com
On 08.02.17 07:01 Mona Gopal wrote:

> A text file with configuration contents would be given to us by the
> product teams. I will have to compare this file against the one on
> the remote host , find out the difference, and replace values for
> the variables where it doesn't match. How is this achievable using
> Ansible. Kindly suggest a solution.

I assume you want to manually control, what the differences are.
Automating this is difficult.

I would use a template task, put the file you just got into your
ansible folder as the template src file and then run the
ansible-playbook command with --check --diff:


# File foobar.yml
- hosts: foobar
tasks:
- template:
src: "file_you_just_got"
dest: "/path/to/file/on/remote/server"
check_mode: yes

Then run the playbook foobar.yml like this:

ansible-playbook foobar.yml --check --diff

Johannes

signature.asc

Brian Coca

unread,
Feb 8, 2017, 1:30:41 PM2/8/17
to Ansible Project
The copy module does this by default, run with --diff --check to see
what 'it would do'


----------
Brian Coca
Reply all
Reply to author
Forward
0 new messages