replace a word with fqdn

23 views
Skip to first unread message

Sneha Haldar

unread,
May 29, 2015, 1:14:09 AM5/29/15
to salt-...@googlegroups.com
Hello, I am using ubuntu 12.04 and I want to replace a word in a file with my systems fqdn or hostname.Can it be possibe using grains or script will be better?If using grains then please give a detailed solution.

tim.h...@gmail.com

unread,
May 29, 2015, 4:14:19 AM5/29/15
to salt-...@googlegroups.com
Doing this on a mobile so bear with me.

If your file is under a file.managed state just call

{{ salt['grains.get']('fqdn') }}

where appropriate

Cheers
Message has been deleted

Jakub Pinkas

unread,
Jun 19, 2015, 4:00:00 AM6/19/15
to salt-...@googlegroups.com
Hello,

grains for this purpose will be better.

Let's have look like on hostname and there are 2 way how to specify value just in file or over context in state:

/path/to/file:
  file.managed:
    - replace: True # To replace everytime
    - source: salt://path/to/file 
    - template: jinja # For resolve the value in the file
    - context: 
      host: {{ grains['host'] }}

The file where source point will look like this:
-- place somewhere in of file --
{{ host }}
-- end of file --

If you want specify value just in the file, remove context definition and in the file edit to:
-- place somewhere of file --
{{ grains['host'] }}
-- end of file --

If you want do this with  grains also provide by default FQDN in grains['fqdn']

Full list what minions return you will get by command from master:
salt 'target' grains.ls

Have a good day!

Dne pátek 29. května 2015 10:14:19 UTC+2 tim.h...@gmail.com napsal(a):
Reply all
Reply to author
Forward
0 new messages