hostname

Example:

# Set the hostname of the target machine to 'dev.frkl.io'.
- hostname:
    hostname: dev.frkl.io

Description

Set system’s hostname according to the platforms recommended practices.

Also add the new hostnames to the line containing '127.0.0.1' in /etc/hosts.

Resources

Variables

Name Type Default Description

hostname

string --

The hostname. Required

Examples

Example 1

Set the hostname of the target machine to 'dev.frkl.io'.

Code
- hostname:
    hostname: dev.frkl.io

Code

doc:
  short_help: Set the hosts hostname.
  help: |
    Set system’s hostname according to the platforms recommended practices.

    Also add the new hostnames to the line containing '127.0.0.1' in /etc/hosts.

  references:
    Blogpost about how to set the hostname on Ubuntu: http://derpturkey.com/setting-host-with-ansible-in-ubuntu/
  examples:
  - title: Set the hostname of the target machine to 'dev.frkl.io'.
    vars:
      hostname: dev.frkl.io

args:
  hostname:
    doc:
      short_help: The hostname.
    type: string
    required: true
    empty: false
    cli:
      param_type: argument

meta:
  tags:
  - networking
  - hostname

frecklets:
- task:
    become: true
  frecklet:
    name: hostname
    type: ansible-module
    properties:
      idempotent: true
      elevated: true
      internet: false
    desc:
      short: "set hostname to '{{:: hostname ::}}'"
      long: |
        Set hostname to '{{:: hostname ::}}' (actual tasks dependent on platform).
  vars:
    name: '{{:: hostname ::}}'
- task:
    become: true
  frecklet:
    name: lineinfile
    type: ansible-module
    properties:
      idempotent: true
      elevated: true
      internet: false
    desc:
      short: "add hostname '{{:: hostname ::}}' to /etc/hosts"
      long: |
        Add the hostname to the line in /etc/hosts that contains '127.0.0.1'.
  vars:
    dest: /etc/hosts
    regexp: ^127\.0\.0\.1[ \t]+localhost
    line: '127.0.0.1 localhost {{:: hostname ::}}'
    state: present
frecklecute hostname --help

Usage: frecklecute hostname [OPTIONS] HOSTNAME

  Set system’s hostname according to the platforms recommended practices.

  Also add the new hostnames to the line containing '127.0.0.1' in
  /etc/hosts.

Options:
  --help  Show this message and exit.
# -*- coding: utf-8 -*-


#
# module path: pycklets.hostname.Hostname
#


from dataclasses import dataclass
from pyckles import AutoPycklet
from typing import *    # noqa

@dataclass
class Hostname(AutoPycklet):
    """Set system’s hostname according to the platforms recommended practices.

     Also add the new hostnames to the line containing '127.0.0.1' in /etc/hosts.

       Args:
         hostname: The hostname.

    """

    FRECKLET_ID = "hostname"

    hostname: str = None


    def __post_init__(self):
        super(Hostname, self).__init__(var_names=["hostname"])


frecklet_class = Hostname
# -*- coding: utf-8 -*-


#
# module path: pycklets.hostname.Hostname
#


from pyckles import AutoPycklet

class Hostname(AutoPycklet):
    """Set system’s hostname according to the platforms recommended practices.

     Also add the new hostnames to the line containing '127.0.0.1' in /etc/hosts.

       Args:
         hostname: The hostname.

    """

    FRECKLET_ID = "hostname"

    def __init__(self, hostname=None):

        super(Hostname, self).__init__(var_names=["hostname"])
        self._hostname = hostname

    @property
    def hostname(self):
        return self._hostname

    @hostname.setter
    def hostname(self, hostname):
        self._hostname = hostname



frecklet_class = Hostname