所以我的configuration.yml(ansible任务)中有这一行
- name: inserting password into database.php
lineinfile: dest=/vagrant/htdocs/app/config/database.php insertbefore="^\s*'pgsql' => array" regexp="^\s*'password'" line=" 'password' => '',"
我正在尝试替换它:
'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' => '',
所以我的正则表达式完全符合我的预期,但是这个前线只是不能像我想的那样工作,关于这个功能的 ansible 文档让我相信它会在最后一个匹配之前 'pgsql' => array
但它只是不断替换最后一条路径,在这种情况下'password' => '',