ローカルにあるファイルをリモート側のサーバに同じファイル名としてコピーした後
ファイル内容が更新された事を確認して
反映コマンドを実行させる事が目的です
前提として、下記のようなディレクトリ・ファイル構成となります
ローカル側の dir/dir-A/test リモート側の dir/dir-X/test と紐づきます
ローカル側の dir/dir-B/test リモート側の dir/dir-Y/test と紐づきます
今、試している事として
copyモジュール実行タスクにおいてファイル内容をdiffした結果をregisterに
入れて、指定した条件と合致すれば反映コマンド実行させようとしています
例えば、msgで出力される値( result.follow )を条件として試しました dry&run結果は下記となりました
"msg": "The conditional check '{{ result.follow == false }}' failed. The error was: error while evaluating conditional ({{ result.follow == false }}): 'dict object' has no attribute 'follow'\n\nThe error appears to be in '/Users/aaaa/git/test-ansible/roles/test/tasks/copy_test.yml': line 27, column 5, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n - name: run command file\n ^ here\n"
また、registerに格納する条件を
when: result.changed == true
とすると、dir-Aとdir-B配下にあるファイルに対してコマンド実行されてしまいます
作成中のansibleは以下となります
########## copy file and run command ########## - name: copy test file copy: src: "{{ item.src }}" dest: "{{ item.dest }}" owner: root group: root mode: 0644 # backup: yes # check_mode: yes diff: yes # register: result with_items: # "{{ copy }}" - { src: dir/dir-A/test, dest: dir/dir-X/test } - { src: dir/dir-B/test, dest: dir/dir-Y/test } register: result - name: excute debug: msg: "{{ result }}" - name: run command command: /usr/sbin/script.sh args: chdir: "/etc/{{ item }}/" when: result.follow == 'false' # when: result.changed == true with_items: - dir-X - dir-Y tags: copy_test
copyモジュールで更新したファイルがあれば、更新したファイルがあるディレクトリ配下にあるファイルを対象のみに、run command実行させるにはどのようにすればよろしいかご教示願います

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2022/09/20 08:47
2022/09/20 11:56
2022/10/24 06:44 編集
2022/09/21 08:10
2022/10/24 06:47 編集
2022/10/06 12:50
2022/10/14 04:37
2022/10/24 06:45