2017-07-03 18 views
0

私は、ファイル内の限られた行の中で "glob"を "url"に置き換えるサンプルユースケースを用意しています。残りのファイルは交換する必要はありません。ファイル内の内容を特定の行だけに置き換えます。

/publishfarm 
     { 
     # client headers which should be passed through to the render instances 
     # (feature supported since dispatcher build 2.6.3.5222) 
     /clientheaders 
      { 
       $include "clientheaders.any" 
      } 
     # hostname globbing for farm selection (virtual domain addressing) 
     /virtualhosts 
      { 
       $include "publish-vhosts.any" 
      } 
     # the load will be balanced among these render instances 
     /renders 
      { 
      $include "publish-renders.any" 
      } 
     # only handle the requests in the following acl. default is 'none' 
     # the glob pattern is matched against the first request line 
     /filter 
      { 
      # deny everything and allow specific entries 
      /0001 { /type "deny" /glob "*" } 

      # open consoles 
     # /0012 { /type "allow" /glob "* /crx/*" } # allow content repository 
     # /0013 { /type "allow" /glob "* /system/*" } # allow OSGi console 

      # allow non-public content directories 
     # /0021 { /type "allow" /glob "* /apps/*" } # allow apps access 
     # /0022 { /type "allow" /glob "* /bin/*" } 


     # /0024 { /type "allow" /glob "* /libs/*" } 
     # /0025 { /type "deny" /glob "* /libs/shindig/proxy*" } # if you enable /libs close access to proxy 

     # /0026 { /type "allow" /glob "* /home/*" } 
     # /0027 { /type "allow" /glob "* /tmp/*" } 
     # /0028 { /type "allow" /glob "* /var/*" } 


      /0023 { /type "allow" /glob "* /content*" } # disable this rule to allow mapped content only 

      # enable specific mime types in non-public content directories 
     /0041 { /type "allow" /glob "* *.css *" } # enable css 
     /0042 { /type "allow" /glob "* *.gif *" } # enable gifs 
     /0043 { /type "allow" /glob "* *.ico *" } # enable icos 
     /0044 { /type "allow" /glob "* *.js *" } # enable javascript 
     /0045 { /type "allow" /glob "* *.png *" } # enable png 
     /0046 { /type "allow" /glob "* *.swf *" } # enable flash 
     /0047 { /type "allow" /glob "* *.svg *" } # enable SVG 
     /0048 { /type "allow" /glob "* *.woff *" } # enable woff 
     /0049 { /type "allow" /glob "* *.ttf *" } # enable ttf 
     /0050 { /type "allow" /glob "* *.eot *" } # enable eot 
     /0051 { /type "allow" /glob "* *.jpg *" } # enable jpg 

     # enable features 
     /0061 { /type "allow" /glob "POST /content/[.]*.form.html" } # allow POSTs to form selectors under content 
     /0062 { /type "allow" /glob "* /libs/cq/personalization/*" } # enable personalization 
     /0063 { /type "allow" /glob "POST /content/[.]*.commerce.cart.json" } # allow POSTs to update the shopping cart 


      # deny content grabbing 
      /0081 { /type "deny" /glob "GET *.infinity.json*" } 
      /0082 { /type "deny" /glob "GET *.tidy.json*"  } 
      /0083 { /type "deny" /glob "GET *.sysview.xml*" } 
      /0084 { /type "deny" /glob "GET *.docview.json*" } 
      /0085 { /type "deny" /glob "GET *.docview.xml*" } 
      /0086 { /type "deny" /glob "GET *.*[0-9].json*" } 
      /0087 { /type "deny" /glob "GET *.feed.xml*"  } 
     # /0088 { /type "allow" /glob "GET *.1.json*"  } # allow one-level json requests 

私はこれらのブロックだけでglobで置き換えることができ、ファイル全体ではありません。私は交換することにしたい 内容は今ここにキャッチは、行番号が固定されていないです

 # enable specific mime types in non-public content directories 
    /0041 { /type "allow" /glob "* *.css *" } # enable css 
    /0042 { /type "allow" /glob "* *.gif *" } # enable gifs 
    /0043 { /type "allow" /glob "* *.ico *" } # enable icos 
    /0044 { /type "allow" /glob "* *.js *" } # enable javascript 
    /0045 { /type "allow" /glob "* *.png *" } # enable png 
    /0046 { /type "allow" /glob "* *.swf *" } # enable flash 
    /0047 { /type "allow" /glob "* *.svg *" } # enable SVG 
    /0048 { /type "allow" /glob "* *.woff *" } # enable woff 
    /0049 { /type "allow" /glob "* *.ttf *" } # enable ttf 
    /0050 { /type "allow" /glob "* *.eot *" } # enable eot 
    /0051 { /type "allow" /glob "* *.jpg *" } # enable jpg 

です。私はどのようにしてこれを不可能な状態で達成することができますか?

私はこれをやっていました:このファイルではvimで41,51s/glob/urlを開いてから、開始と終了行に注意してください。しかし私が言ったように、これらの行番号は変わり続ける。

+0

私の答えがあなたの質問に答えるならば、私はそのように印をつけていただければ幸いです。もしそうでなければ、私はそれがどのように改善できるかを知ることができる。 – rasebo

答えて

-1

enable gifsなどを含む行をすべて検索し、globurlに置き換えるスクリプトを作成することをお勧めします。

0

私は、次のコマンドでこれを行うことができました:

# ansible 127.0.0.1 -m replace -a "path='/my/path/test_file' regexp='W*(/glob)\W*(.*)W*(css)W*(.*)css$' replace='url \"* *.css *\" } # enable css'" 

それは「CSS」で終わる場合W*(/glob)\W*(.*)W*(css)W*(.*)css$正規表現は「グロブ」とラインの端部との間のすべてを一致します。

- replace: 
    path: /my/path/test_file 
    regexp: 'W*(/glob)\W*(.*)W*(css)W*(.*)css$' 
    replace: 'url \"* *.css *\" } # enable css'' 
この方法の欠点は、あなたがCSSの各ブロックを交換する必要がありますどちらかということです

、GIFを、ICOS、ジャバスクリプトなど

:タスクファイル内でこのに変換する必要があり

ので、より良いアプローチはwith_itemsを使用して、拡張子を処理し、私たちはそうのように試合をやっている時にコメントを次のようになります。

- hosts: myhostgroup 
    tasks: 
    - replace: 
     path: /my/path/test_file 
     regexp: 'W*(/glob)\W*(.*)W*({{ item.extension }})W*(.*){{ item.comment }}$' 
     replace: 'url "* *.{{ item.extension }} *" } # enable {{ item.comment }}' 
     with_items: 
     - { extension: 'css', comment: 'css' } 
     - { extension: 'gif', comment: 'gifs' } 
     - { extension: 'ico', comment: 'icos' } 
     - { extension: 'js', comment: 'javascript' } 
     - { extension: 'png', comment: 'png' } 
     - { extension: 'swf', comment: 'flash' } 
     - { extension: 'svg', comment: 'SVG' } 
     - { extension: 'woff', comment: 'woff' } 
     - { extension: 'ttf', comment: 'ttf' } 
     - { extension: 'eot', comment: 'eot' } 
     - { extension: 'jpg', comment: 'jpg' } 

私は正規表現が共同確信していますuldは改善されましたが、これはあなたのファイルに対する私のテストのために働いていました。

関連する問題