2016-08-26 6 views
0

はので、私は(ansibleタスク)は:完全に間違ったことをして、

- name: inserting password into database.php 
    lineinfile: dest=/vagrant/htdocs/app/config/database.php insertbefore="^\s*'pgsql' => array" regexp="^\s*'password'" line="      'password' => ''," 

私configuration.ymlでこのラインを持っている理由私は見当もつかないし、私はこれを交換しようとしています:

'sqlite' => array(
     'driver' => 'sqlite', 
     'database' => __DIR__.'/../database/production.sqlite', 
     'prefix' => '', 
    ), 
    'mysql' => array(
     'driver' => 'mysql', 
     'host'  => 'localhost', 
     'database' => 'echoit', 
     'username' => 'root', 
     'password' => 'vp45tudsdt', 
     'charset' => 'utf8', 
     'collation' => 'utf8_unicode_ci', 
     'prefix' => '', 
     'port'  => 8889 
    ), 
'pgsql' => array(
     'driver' => 'pgsql', 
     'host'  => 'localhost', 
     'database' => 'forge', 
     'username' => 'forge', 
     'password' => '', 
     'charset' => 'utf8', 
     'prefix' => '', 
     'schema' => 'public', 
    ), 

私は正規表現をgrep検索してみてください。

grep "^\s*'pgsql' => array" ./htdocs/app/config/database.default.php 


'pgsql' => array(

、私は他のものをgrepする:

grep "^\s*'password'" ./htdocs/app/config/database.php 


       'password' => 'xxxxxxx', 
       'password' => '', 
      'password' => '', 

だから私の正規表現は、私が期待する正確なものと一致し が、私はそれが希望thouthとして、このbeforelineがうまく動作しない、ansibleこの機能に関するドキュメントは、それが'pgsql' => array前の最後の試合を取るだろうと信じるように私を導いたが、それは単にどこナンプラーを決定するために使用されている。この場合'password' => '',

答えて

2

insertafterinsertbeforeで、非常に最後のパスを交換し続けます新しい行regexpが見つからない場合、それは検索エリアを制限していません。
documentationあたりとして:

regexp - ファイルのすべての行で検索する正規表現。

+0

ああ、私はそれを気付かなかった、ありがとう。 – DenLilleMand

1

ベストプラクティス:template moduleを使用:dbconn.php.j2

内容:

<?php 

// {{ ansible_managed }} 

$DBHost = 'localhost'; 
$DBName = '{{ db.dbname }}'; 
$DBLogin = '{{ db_user.name }}'; 
$DBPassword = '{{ db_user.password }}'; 

?> 

のparams 'デシベル'、 'DBUSER' のhost_varsgroup_vars、パスワードに格納されている - ansible vaultに。脚本で

タスク:あなたはgitのを使用している場合

- name: template config files 
    template: 
    src="sites_params/{{ sitename }}/templates/include/dbconn.php.j2" 
    dest="/www/{{ sitename }}/www/include/dbconn.php" 
    owner=apache 
    group=apache 
    mode=0644 
    setype=httpd_sys_content_t 

PSは、ちょうどあなたのプロジェクトにファイルを(ETC塩、パスワードなし)サンプル設定を入れて、このようにgitからdbconnとしてあなたのconfigファイルを除外します。

+0

さて、ありがとう、私はそれを調べます:)私はそれを控えていた理由は、私は設定ファイルを無駄なもので捨てなければならないということでしたが、おそらくそれを行う方法です。 – DenLilleMand

関連する問題