Deployer: Getting hostname

Created on 14 Feb 2018  路  9Comments  路  Source: deployphp/deployer

| 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

Description

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 ?

bug

Most helpful comment

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.

All 9 comments

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}}

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ovaiskhan11 picture ovaiskhan11  路  4Comments

lsv picture lsv  路  4Comments

exts picture exts  路  3Comments

dima-stefantsov picture dima-stefantsov  路  5Comments

timkley picture timkley  路  4Comments