いつもお世話になっております。
変数を使用して、ファイルパスを組み立てる処理を書いています。
src_dir
を省略可能な変数として使用したいのですが、
今の書き方だと省略時にスラッシュが重なってしまいます。
その後の動作に影響がないことは分かっているのですが、
あんまり気持ちが良いものではありません :(
何か良い方法はないでしょうか?
join
が使えるかもしれないと思い、試したコードも載せておきます。
よろしくお願いします。
--- - hosts: all gather_facts: no tasks: - debug: msg={{ dotfiles_dest }}/{{ item.src_dir | default() }}/{{ item.src }} with_items: dotfiles_dotfiles - debug: msg={{ [ dotfiles_dest, item.src_dir | default(), item.src ] | join("/") }} with_items: dotfiles_dotfiles vars: dotfiles_dest: ~/.dotfiles dotfiles_dotfiles: - { src: foo } - { src_dir: bar, src: foo }
TASK: [debug msg={{ dotfiles_dest }}/{{ item.src_dir | default() }}/{{ item.src }}] *** ok: [127.0.0.1] => (item={'src': 'foo'}) => { "item": { "src": "foo" }, "msg": "~/.dotfiles//foo" } ok: [127.0.0.1] => (item={'src_dir': 'bar', 'src': 'foo'}) => { "item": { "src": "foo", "src_dir": "bar" }, "msg": "~/.dotfiles/bar/foo" } TASK: [debug msg={{ [ dotfiles_dest, item.src_dir | default(), item.src ] | join("/") }}] *** ok: [127.0.0.1] => (item={'src': 'foo'}) => { "item": { "src": "foo" }, "msg": "~/.dotfiles//foo" } ok: [127.0.0.1] => (item={'src_dir': 'bar', 'src': 'foo'}) => { "item": { "src": "foo", "src_dir": "bar" }, "msg": "~/.dotfiles/bar/foo" }
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2015/07/27 12:37