util

package
v0.0.0-...-7a6d879 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 29, 2020 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	OKCode                 = 0
	DockerRunCode          = 2
	AnsibleSyntaxCode      = 10
	AnsibleRunCode         = 11
	AnsibleIdempotenceCode = 12
	NotARoleCode           = 20
)

This file contains a full reference of all exit codes.

View Source
var CentOS = Family{
	"CentOS",
	"/sbin/init",
	"/sys/fs/cgroup:/sys/fs/cgroup:ro",
}

CentOS Family Distribution Identifier

View Source
var CentOS6 = Distribution{
	"",
	"centos6",
	true,
	"fubarhouse/docker-ansible:centos-6",
	"fubarhouse",
	"centos6",
	CentOS,
}

CentOS6 Distribution declaration

View Source
var CentOS7 = Distribution{
	"",
	"centos7",
	true,
	"fubarhouse/docker-ansible:centos-7",
	"fubarhouse",
	"centos7",
	CentOS,
}

CentOS7 Distribution declaration

View Source
var Debian = Family{
	"Debian",
	"/bin/systemd",
	"/sys/fs/cgroup:/sys/fs/cgroup:ro",
}

Debian Family Distribution Identifier

View Source
var DebianBuster = Distribution{
	"",
	"buster",
	true,
	"fubarhouse/docker-ansible:buster",
	"fubarhouse",
	"debian10",
	Debian,
}

DebianBuster Distribution declaration

View Source
var DebianJessie = Distribution{
	"",
	"jessie",
	true,
	"fubarhouse/docker-ansible:jessie",
	"fubarhouse",
	"debian8",
	Debian,
}

DebianJessie Distribution declaration

View Source
var DebianStretch = Distribution{
	"",
	"stretch",
	true,
	"fubarhouse/docker-ansible:stretch",
	"fubarhouse",
	"debian9",
	Debian,
}

DebianStretch Distribution declaration

View Source
var DebianWheezy = Distribution{
	"",
	"wheezy",
	true,
	"fubarhouse/docker-ansible:wheezy",
	"fubarhouse",
	"debian7",
	Debian,
}

DebianWheezy Distribution declaration

Distributions is a slice of all distributions listed above.

View Source
var Fedora = Family{
	"Fedora",
	"/usr/lib/systemd/systemd",
	"/sys/fs/cgroup:/sys/fs/cgroup:ro",
}

Fedora Family Distribution Identifier

View Source
var Fedora24 = Distribution{
	"",
	"fedora24",
	true,
	"fubarhouse/docker-ansible:fedora-24",
	"fubarhouse",
	"fedora24",
	Fedora,
}

Fedora24 Distribution declaration

View Source
var Fedora25 = Distribution{
	"",
	"fedora25",
	true,
	"fubarhouse/docker-ansible:fedora-25",
	"fubarhouse",
	"fedora25",
	Fedora,
}

Fedora25 Distribution declaration

View Source
var Fedora26 = Distribution{
	"",
	"fedora26",
	true,
	"fubarhouse/docker-ansible:fedora-26",
	"fubarhouse",
	"fedora26",
	Fedora,
}

Fedora26 Distribution declaration

View Source
var Fedora27 = Distribution{
	"",
	"fedora27",
	true,
	"fubarhouse/docker-ansible:fedora-27",
	"fubarhouse",
	"fedora27",
	Fedora,
}

Fedora27 Distribution declaration

View Source
var Fedora28 = Distribution{
	"",
	"fedora28",
	true,
	"fubarhouse/docker-ansible:fedora-28",
	"fubarhouse",
	"fedora28",
	Fedora,
}

Fedora28 Distribution declaration

View Source
var Fedora29 = Distribution{
	"",
	"fedora29",
	true,
	"fubarhouse/docker-ansible:fedora-29",
	"fubarhouse",
	"fedora29",
	Fedora,
}

Fedora29 Distribution declaration

View Source
var Fedora30 = Distribution{
	"",
	"fedora30",
	true,
	"fubarhouse/docker-ansible:fedora-30",
	"fubarhouse",
	"fedora30",
	Fedora,
}

Fedora30 Distribution declaration

View Source
var Fedora31 = Distribution{
	"",
	"fedora31",
	true,
	"fubarhouse/docker-ansible:fedora-31",
	"fubarhouse",
	"fedora31",
	Fedora,
}

Fedora31 Distribution declaration

View Source
var JeffCentOS6 = Distribution{
	"",
	"centos6",
	true,
	"geerlingguy/docker-centos6-ansible:latest",
	"geerlingguy",
	"centos6",
	CentOS,
}

JeffCentOS6 Distribution declaration

View Source
var JeffCentOS7 = Distribution{
	"",
	"centos7",
	true,
	"geerlingguy/docker-centos7-ansible:latest",
	"geerlingguy",
	"centos7",
	CentOS,
}

JeffCentOS7 Distribution declaration

View Source
var JeffDebian8 = Distribution{
	"",
	"debian8",
	true,
	"geerlingguy/docker-debian8-ansible:latest",
	"geerlingguy",
	"debian8",
	Debian,
}

JeffDebian8 Distribution declaration

View Source
var JeffDebian9 = Distribution{
	"",
	"debian9",
	true,
	"geerlingguy/docker-debian9-ansible:latest",
	"geerlingguy",
	"debian9",
	Debian,
}

JeffDebian9 Distribution declaration

View Source
var JeffFedora24 = Distribution{
	"",
	"fedora24",
	true,
	"geerlingguy/docker-fedora24-ansible:latest",
	"geerlingguy",
	"fedora24",
	Fedora,
}

JeffFedora24 Distribution declaration

View Source
var JeffFedora27 = Distribution{
	"",
	"fedora27",
	true,
	"geerlingguy/docker-fedora27-ansible:latest",
	"geerlingguy",
	"fedora27",
	Fedora,
}

JeffFedora27 Distribution declaration

View Source
var JeffUbuntu1204 = Distribution{
	"",
	"ubuntu1204",
	true,
	"geerlingguy/docker-ubuntu1204-ansible:latest",
	"geerlingguy",
	"ubuntu1204",
	Ubuntu,
}

JeffUbuntu1204 Distribution declaration

View Source
var JeffUbuntu1404 = Distribution{
	"",
	"ubuntu1404",
	true,
	"geerlingguy/docker-ubuntu1404-ansible:latest",
	"geerlingguy",
	"ubuntu1404",
	Ubuntu,
}

JeffUbuntu1404 Distribution declaration

View Source
var JeffUbuntu1604 = Distribution{
	"",
	"ubuntu1604",
	true,
	"geerlingguy/docker-ubuntu1604-ansible:latest",
	"geerlingguy",
	"ubuntu1604",
	Ubuntu,
}

JeffUbuntu1604 Distribution declaration

View Source
var JeffUbuntu1804 = Distribution{
	"",
	"ubuntu1804",
	true,
	"geerlingguy/docker-ubuntu1804-ansible:latest",
	"geerlingguy",
	"ubuntu1804",
	Ubuntu,
}

JeffUbuntu1804 Distribution declaration

View Source
var Ubuntu = Family{
	"Ubuntu",
	"/sbin/init",
	"/sys/fs/cgroup:/sys/fs/cgroup:ro",
}

Ubuntu Family Distribution Identifier

View Source
var Ubuntu1204 = Distribution{
	"",
	"ubuntu1204",
	true,
	"fubarhouse/docker-ansible:precise",
	"fubarhouse",
	"ubuntu1204",
	Ubuntu,
}

Ubuntu1204 Distribution declaration

View Source
var Ubuntu1210 = Distribution{
	"",
	"ubuntu1210",
	true,
	"fubarhouse/docker-ansible:quantal",
	"fubarhouse",
	"ubuntu1210",
	Ubuntu,
}

Ubuntu1210 Distribution declaration

View Source
var Ubuntu1304 = Distribution{
	"",
	"ubuntu1304",
	true,
	"fubarhouse/docker-ansible:raring",
	"fubarhouse",
	"ubuntu1304",
	Ubuntu,
}

Ubuntu1304 Distribution declaration

View Source
var Ubuntu1310 = Distribution{
	"",
	"ubuntu1310",
	true,
	"fubarhouse/docker-ansible:saucy",
	"fubarhouse",
	"ubuntu1310",
	Ubuntu,
}

Ubuntu1310 Distribution declaration

View Source
var Ubuntu1404 = Distribution{
	"",
	"ubuntu1404",
	true,
	"fubarhouse/docker-ansible:trusty",
	"fubarhouse",
	"ubuntu1404",
	Ubuntu,
}

Ubuntu1404 Distribution declaration

View Source
var Ubuntu1410 = Distribution{
	"",
	"ubuntu1410",
	true,
	"fubarhouse/docker-ansible:utopic",
	"fubarhouse",
	"ubuntu1410",
	Ubuntu,
}

Ubuntu1410 Distribution declaration

View Source
var Ubuntu1504 = Distribution{
	"",
	"ubuntu1504",
	true,
	"fubarhouse/docker-ansible:vivid",
	"fubarhouse",
	"ubuntu1504",
	Ubuntu,
}

Ubuntu1504 Distribution declaration

View Source
var Ubuntu1510 = Distribution{
	"",
	"ubuntu1510",
	true,
	"fubarhouse/docker-ansible:wily",
	"fubarhouse",
	"ubuntu1510",
	Ubuntu,
}

Ubuntu1510 Distribution declaration

View Source
var Ubuntu1604 = Distribution{
	"",
	"ubuntu1604",
	true,
	"fubarhouse/docker-ansible:xenial",
	"fubarhouse",
	"ubuntu1604",
	Ubuntu,
}

Ubuntu1604 Distribution declaration

View Source
var Ubuntu1610 = Distribution{
	"",
	"ubuntu1610",
	true,
	"fubarhouse/docker-ansible:yakkety",
	"fubarhouse",
	"ubuntu1610",
	Ubuntu,
}

Ubuntu1610 Distribution declaration

View Source
var Ubuntu1704 = Distribution{
	"",
	"ubuntu1704",
	true,
	"fubarhouse/docker-ansible:zesty",
	"fubarhouse",
	"ubuntu1704",
	Ubuntu,
}

Ubuntu1704 Distribution declaration

View Source
var Ubuntu1710 = Distribution{
	"",
	"ubuntu1710",
	true,
	"fubarhouse/docker-ansible:artful",
	"fubarhouse",
	"ubuntu1710",
	Ubuntu,
}

Ubuntu1710 Distribution declaration

View Source
var Ubuntu1804 = Distribution{
	"",
	"ubuntu1804",
	true,
	"fubarhouse/docker-ansible:bionic",
	"fubarhouse",
	"ubuntu1804",
	Ubuntu,
}

Ubuntu1804 Distribution declaration

View Source
var Ubuntu1810 = Distribution{
	"",
	"ubuntu1810",
	true,
	"fubarhouse/docker-ansible:cosmic",
	"fubarhouse",
	"ubuntu1810",
	Ubuntu,
}

Ubuntu1810 Distribution declaration

View Source
var Ubuntu1904 = Distribution{
	"",
	"ubuntu1904",
	true,
	"fubarhouse/docker-ansible:disco",
	"fubarhouse",
	"ubuntu1904",
	Ubuntu,
}

Ubuntu1904 Distribution declaration

View Source
var Ubuntu2004 = Distribution{
	"",
	"ubuntu2004",
	true,
	"fubarhouse/docker-ansible:focal",
	"fubarhouse",
	"ubuntu2004",
	Ubuntu,
}

Ubuntu2004 Distribution declaration

Functions

func AnsiblePlaybook

func AnsiblePlaybook(args []string, stdout bool) (string, error)

AnsiblePlaybook will execute a command to the ansible-playbook binary and use the input args as arguments for that process. You can request output be printed using the bool stdout.

func CustomDistributionValueGet

func CustomDistributionValueGet(dist *Distribution, key string) (string, error)

CustomDistributionValueGet will get a field value from a Distribution.

func CustomDistributionValueSet

func CustomDistributionValueSet(dist *Distribution, key, value string) error

CustomDistributionValueSet will set a field to a given value from a Distribution.

func CustomFamilyValueGet

func CustomFamilyValueGet(family *Family, key string) (string, error)

CustomFamilyValueGet will get a field value from a Family.

func CustomFamilyValueSet

func CustomFamilyValueSet(family *Family, key, value string) error

CustomFamilyValueSet will set a field to a given value from a Family.

func DockerExec

func DockerExec(args []string, stdout bool) (string, error)

DockerExec will execute a command to the docker binary and use the input args as arguments for that process. You can request output be printed using the bool stdout.

func GenericFileAssignment

func GenericFileAssignment(input, path string, check bool) (string, error)

GenericFileAssignment will take a path and parse check it for specific matches for file paths, and then find the given paths. - Absolute paths are inputs starting with / and remain unmodified. - Relative paths are inputs starting with ./ and append the source or pwd. - Empty paths are unmodified. Results are checked against os.Stat and the results are returned with an error or nil.

func GenericPlaybookAssignment

func GenericPlaybookAssignment(input, path string) (string, error)

GenericPlaybookAssignment will return the path of the only available playbook file under the roles tests directory, to be used when the default playbook path is invalid.

func GitCmd

func GitCmd(path string, args []string) (string, error)

GitCmd will run git commands in the specified directory.

func IdempotenceResult

func IdempotenceResult(output string) bool

IdempotenceResult will get the result of an idempotence test which is the full output of a role, and it will identify each of the applicable checks for idempotence. In this case, we simply need the values of changed and failed and some basic logic.

func MapInventory

func MapInventory(CID string, config *AnsibleConfig)

MapInventory will adjust the inventory path for the appropriate path based on the configuration. ie remote or not, and guesswork based upon input. For example, paths starting with /, ./ or otherwise.

func MapPlaybook

func MapPlaybook(config *AnsibleConfig)

MapPlaybook will adjust the playbook path for the appropriate path based on the configuration. ie remote or not, and guesswork based upon input. For example, paths starting with /, ./ or otherwise.

func MapRequirements

func MapRequirements(config *AnsibleConfig)

MapRequirements will adjust the requirements path for the appropriate path based on the configuration. ie remote or not, and guesswork based upon input. For example, paths starting with /, ./ or otherwise.

func PrintIdempotenceResult

func PrintIdempotenceResult(start time.Time, idempotence bool)

PrintIdempotenceResult will log the results of the idempotence checks.

Types

type AnsibleConfig

type AnsibleConfig struct {

	// HostPath is the path to the directory containing the role
	// on the host machine, which could be anywhere.
	HostPath string

	// Inventory is the inventory argument in Ansible commands.
	// in this case we are focusing on inventory files or inline dicts.
	// Example: 'container_name,' or './tests/inventory.
	Inventory string

	// RemotePath is the path to the roles folder on the container
	// which should represent the roles folder (ie /etc/ansible/roles)
	RemotePath string

	// ExtraRolesPath is the path to the roles folder on the host which will
	// be mounted on the container to "/root/.ansible/roles" and available to the playbook
	// as dependencies. This is a useful workaround for CI/CD environments where the roles
	// are already downloaded on the host, or if the roles are in private git repos.
	ExtraRolesPath string

	// LibraryPath is the path to the library folder on the host which will
	// be mounted on the container to "/root/.ansible/library".
	LibraryPath string

	// The path to the requirements file relative to HostPath.
	// Requirements will not attempt installation if the field
	// does not have a value (when value == "")
	RequirementsFile string

	// PlaybookFile is the path to the playbook located in the
	// tests file relative to HostPath (ie HostPath/tests/playbook.yml)
	PlaybookFile string

	// Remote indicates the playbook will be run on a remote host
	// likely which is inputted to the inventory field.
	Remote bool

	// verbose
	Verbose bool

	// Quiet will determine if all reporting mechanisms are hidden.
	Quiet bool
}

AnsibleConfig represents a series of configuration options for an ansible command to be executed.

func (*AnsibleConfig) IsAnsibleRole

func (config *AnsibleConfig) IsAnsibleRole() bool

IsAnsibleRole will identify if the mounted directory is an Ansible role.

type AnsibleReport

type AnsibleReport struct {
	Meta struct {
		Timestamp    time.Time
		Repository   string
		CommitHash   string
		LocalChanges bool
		ReportFile   string
	}
	Ansible struct {
		Config       AnsibleConfig
		Distribution Distribution
		Hosts        []string
		Syntax       bool
		Requirements bool
		Run          struct {
			Result bool
			Time   time.Duration
		}
		Idempotence struct {
			Result bool
			Time   time.Duration
		}
	}
	Docker struct {
		Run     bool
		Kill    bool
		Volumes []string
	}
}

AnsibleReport will contain metadata about the run which will be, is and has executed.

func NewReport

func NewReport(config *AnsibleConfig) AnsibleReport

NewReport will generate a new Report variable from the input configuration.

func (*AnsibleReport) GetJSON

func (report *AnsibleReport) GetJSON(data interface{}) ([]byte, error)

GetJSON will return an unmarhaled object as JSON.

func (*AnsibleReport) GetYAML

func (report *AnsibleReport) GetYAML(data interface{}) ([]byte, error)

GetYAML will return an unmarhaled object as YAML.

func (*AnsibleReport) IsGit

func (report *AnsibleReport) IsGit() bool

IsGit will abstract the private func from the report.

func (*AnsibleReport) Printf

func (report *AnsibleReport) Printf()

Printf will print the report in a formatted way.

type Container

type Container interface {
	DockerRun(config *AnsibleConfig)
	DockerKill()
	RoleInstall(config *AnsibleConfig)
	RoleTest(config *AnsibleConfig)
}

Container is an interface which allows a user from plugging in a Distribution to use these functions to dockerRun Ansible tests. Details on

type Distribution

type Distribution struct {

	// CID is the name/id of the container.
	CID string

	// Name is the identifying name of the distribution
	Name string

	// Privileged is a boolean to indicate to use privileged
	Privileged bool

	// The fully qualified container name in the format:
	// name/image:version - ie fubarhouse/docker-ansible:bionic
	Container string

	// User is the user associated to the image file, used
	// when searching for a user from the command line tool.
	User string

	// Distro is the distro associated to the image file, used
	// when searching for a distro from the command line tool.
	Distro string

	// Family associated to this distribution.
	Family Family
}

A Distribution declares the options to pass to Docker to dockerRun and test the container.

func GetDistribution

func GetDistribution(container, target, init, volume, user, distro string) (Distribution, error)

GetDistribution will get the distribution object to allow dynamic loading of different distributions. A suitable struct will be compiled from the inputs and returned with an error if the specified container cannot be found.

func NewCustomDistribution

func NewCustomDistribution() *Distribution

NewCustomDistribution will return an empty distribution.

func (*Distribution) AnsibleHosts

func (dist *Distribution) AnsibleHosts(config *AnsibleConfig, report *AnsibleReport) ([]string, error)

func (*Distribution) DockerCheck

func (dist *Distribution) DockerCheck() bool

DockerCheck checks if the specified container is running.

func (*Distribution) DockerKill

func (dist *Distribution) DockerKill(quiet bool) bool

DockerKill will stop the container and remove it.

func (*Distribution) DockerRun

func (dist *Distribution) DockerRun(config *AnsibleConfig, report *AnsibleReport) bool

DockerRun will launch a new container (containerID) using the fields in a AnsibleConfig struct.

func (*Distribution) IdempotenceTest

func (dist *Distribution) IdempotenceTest(config *AnsibleConfig) (bool, time.Duration)

IdempotenceTest will run an Ansible playbook once and check the output for any changed or failed tasks as reported by Ansible.

func (*Distribution) IdempotenceTestRemote

func (dist *Distribution) IdempotenceTestRemote(config *AnsibleConfig) (bool, time.Duration)

IdempotenceTestRemote will run an Ansible playbook once and check the output for any changed or failed tasks as reported by Ansible.

func (*Distribution) RoleInstall

func (dist *Distribution) RoleInstall(config *AnsibleConfig) bool

RoleInstall will install the requirements if the file is configured.

func (*Distribution) RoleSyntaxCheck

func (dist *Distribution) RoleSyntaxCheck(config *AnsibleConfig) bool

RoleSyntaxCheck will run a syntax check of the mounted volume inside of the active container. This helps with pure isolation of the syntax to separate it from other potential Ansible versions.

func (*Distribution) RoleSyntaxCheckRemote

func (dist *Distribution) RoleSyntaxCheckRemote(config *AnsibleConfig) bool

RoleSyntaxCheckRemote will run a syntax check of the specified container. This helps with pure isolation of the syntax to separate it from other potential Ansible versions.

func (*Distribution) RoleTest

func (dist *Distribution) RoleTest(config *AnsibleConfig) (bool, time.Duration)

RoleTest will execute the specified playbook inside the container once. It will assemble a request to pass into the Docker execution function DockerRun.

func (*Distribution) RoleTestRemote

func (dist *Distribution) RoleTestRemote(config *AnsibleConfig) (bool, time.Duration)

RoleTestRemote will execute the specified playbook outside the container once. It will assemble a request to pass into the Docker execution function DockerRun.

type Family

type Family struct {
	Name       string
	Initialise string
	Volume     string
}

Family is a set of characteristics describing a family of linux distributions. For example, ubuntu, centos, debian or fedora.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL