Ansible - Write variable to config file -


we have redis configurations differs on port , maxmemory settings, i'm looking way write 'base' config file redis , replace port , maxmemory variables.

can ansible?

for such operations lineinfile module works best; example:

- name: ensure maxmemory set 2 mb   lineinfile:     dest: /path/to/redis.conf     regexp: maxmemory     line: maxmemory 2mb 

or change multiple lines in 1 task with_items:

- name: ensure redis parameters configured   lineinfile:     dest: /path/to/redis.conf     regexp: "{{ item.line_to_match }}"     line: "{{ item.line_to_configure }}"   with_items:     - { line_to_match: "line_to_match", line_to_configure: "maxmemory 2mb" }     - { line_to_match: "port", line_to_configure: "port 4096" } 

or if want create base config, write in jinja2 , use template module:

vars:   redis_maxmemory: 2mb   redis_port: 4096  tasks:   - name: ensure redis configured     template:       src: redis.conf.j2       dest: /path/to/redis.conf 

with redis.conf.j2 containing:

maxmemory {{ redis_maxmemory }} port {{ redis_port }} 

Comments

Popular posts from this blog

account - Script error login visual studio DefaultLogin_PCore.js -

xcode - CocoaPod Storyboard error: -