问题原文
原帖链接 · user5447339 · CC BY-SA 4.0
I have a file test_proc.init in a particular directory. And I have one more file desc.cmd in the same directory which has below content:
set_poc 204 6
send_data_file goldy_proc.init 4e8ee8946f7a89d2eb501a752c5e3ee6ea266e5b
set_poc 204 7
send_data_file goldy_proc.init 4e8ee8946f7a89d2eb501a752c5e3ee6ea266e5b
set_poc 204 8
send_data_file goldy_proc.init 4e8ee8946f7a89d2eb501a752c5e3ee6ea266e5b
set_poc 204 9
send_data_file goldy_proc.init 4e8ee8946f7a89d2eb501a752c5e3ee6ea266e5b
Below is what I want to do:
- I want to get the
sha1sumoftest_proc.initfile:sha1sum test_proc.init. - And whatever is the output from that
sha1sumcommand, I want to copy that checksum and update thedesc.cmdfile.
So if new checksum is e32313118e53b60140d2024dfa7578c3fd89b346 the my desc.cmd file will be like this:
set_poc 204 6
send_data_file goldy_proc.init e32313118e53b60140d2024dfa7578c3fd89b346
set_poc 204 7
send_data_file goldy_proc.init e32313118e53b60140d2024dfa7578c3fd89b346
set_poc 204 8
send_data_file goldy_proc.init e32313118e53b60140d2024dfa7578c3fd89b346
set_poc 204 9
send_data_file goldy_proc.init e32313118e53b60140d2024dfa7578c3fd89b346
Is this possible to do in ansible? I am not sure on how can I paste the checksum and update the file.
- name: Get sha1sum of file
stat:
path: /data/test_proc.init
checksum_algorithm: sha1sum
get_checksum: yes
register: shell_stat
社区高分解答
原帖链接 · Henrik Pingel · CC BY-SA 4.0
The output of the stat command should already contain the sha of the file:
- name: Get sha1sum of file
stat:
path: /data/test_proc.init
checksum_algorithm: sha1sum
get_checksum: yes
register: sha
It can than be used with a module like lineinfile or blockinfile to update the desc.cmd file like this:
- name: insert sha
lineinfile:
path: /data/desc.cmd
line: "{{ sha.stat.checksum }}"
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
