将.txt文件内容复制到特定位置的.php文件

I cannot solve this for few hours already.

In my webserver vm in var/www/html folder i have: 1) db_ip.txt file with IP in it (10.10.10.10) 2) connection.php file:

<?php
$link = mysqli_connect("localhost", "root", "root", "db_name");
/* check connection */
if (mysqli_connect_errno()) {
    printf("Connect failed: %s
", mysqli_connect_error());
    exit();
}

How can I replace the localhost with the ip, located in db_ip.txt file in ansible playbook?

You can use file_get_contents function to solve this.

<?php
$source = file_get_contents("db_ip.txt");
$link = mysqli_connect($source, "root", "root", "db_name");
/* check connection */
if (mysqli_connect_errno()) {
    printf("Connect failed: %s
", mysqli_connect_error());
    exit();
}

</div>

Use .ini instead of text like :

[db]
host = 1.1.1.1

In your code so the following: // Parse with sections

$ini_array = parse_ini_file("sample.ini", true);
print_r($ini_arrat["db"]["host"]);