| Q | A
| ----------------- | ---
| Issue Type | Bug
| Deployer Version | master (6.0 but --version always return master)
| Local Machine OS | macOS
| Remote Machine OS | Debian 8.10
In my old recipe, I had tasks which execute commands locally, to the remote host
task('fetch:archives', function () {
runLocally("scp -r {{server.hostname}}:{{current_path}}/dump/", 0);
})->desc('Fetch archives from server');
But it seems I can't get my hostname anymore:
{{server}} of course does not exists anymore, but {{hostname}} or get('hostname') returns host instead of host()->hostname().
How can I achieve this and by the way, get the while current host configuration ?
Try this:
set('real_hostname', function () {
Context::get()->getHost()->getHostname();
});
Actually I don't like this too. I think I'll refactor this in v7.
Thanks, but I'm afraid, I can't get the real hostname, but the host actually defined in the deploy recipe.
Task\Context::get()->getHost()->getHostname()
Give me prod instead of my.site.com
I could set the host using its real hostname
host('my.site.com')
->stage('production')
->set('deploy_path', $path . '/preprod');
instead of
host('prod')
->hostname('my.site.com');
->stage('production')
->set('deploy_path', $path . '/preprod');
but I couldn't be able to use multiple stages for one host anymore as all hosts definitions would get the exact same name.
I see, there is problem with stages - will be solved in next release. Use getHostname() for first example.
The fix is already open as a PR I guess?
https://github.com/deployphp/deployer/pull/1434
@staabm yes, but I don't like solution. I think to refactor this in v7 into hostname -> alias, real_hostname -> hostname.
On Deployer 6.2.0, I had to modify @antonmedv example like this to make it work:
set('real_hostname', function () {
return Task\Context::get()->getHost()->getHostname();
});
Then use get('real_hostname') in your custom task.
I couldn't get this approach to work in version 6.4.3. It always returns the value set for host rather than the value set for hostname.
Anything I might be missing?
Fixed in #1904
Not it will be always correct hostname {{hostname}}
Most helpful comment
On Deployer
6.2.0, I had to modify @antonmedv example like this to make it work:Then use
get('real_hostname')in your custom task.