Skip to content

Set hostname? #40

Closed
Closed

Description

@ericclemmons

If a machine is created with a hostname already set (by rackspace, vcenter, etc.), it may have a name like new4.

Upon provisioning, it should have a name like staging.mysite.com, so the user knows which machine they're on.

Activity

  1. EvanK commented on Oct 29, 2013

    @EvanK
    Contributor

    In bash, this would be fairly simple:

    # new host to use
    NEW_HOSTNAME="staging.mysite.com"
    # grab old host to replace
    OLD_HOSTNAME=$(hostname)
    # hostname change to apply before restart
    sudo hostname $NEW_HOSTNAME
    # hostname change to apply after restart
    echo $NEW_HOSTNAME | sudo tee /etc/hostname
    # replace any uses of old in /etc/hosts
    sudo sed -i "s/${OLD_HOSTNAME}/${NEW_HOSTNAME}/g" /etc/hosts

    Should translate easily enough to ansible...?

  2. EvanK commented on Oct 29, 2013

    @EvanK
    Contributor

    Looking into this, and maybe a stupid question: I know we have a ${domain} global var available in the ansible tasks...do we have any way to see what stage we're running under? (eg, to get the full hostname we're wanting to set)

  3. EvanK commented on Oct 30, 2013

    @EvanK
    Contributor

    Good news: we can eventually replace much of whatever we do for this with ansible/ansible#3940

    Update: that PR was merged and looks like it will be part of ansible's next 1.4.* release

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions