Merge pull request #195 from baby-gnu/ci/force-hostname
test(inspec): use static hostname in mapdata
This commit is contained in:
commit
cf9abf5e5a
@ -149,6 +149,8 @@ verifier:
|
||||
|
||||
suites:
|
||||
- name: default
|
||||
driver:
|
||||
hostname: example.net
|
||||
provisioner:
|
||||
state_top:
|
||||
base:
|
||||
|
@ -1,12 +1,7 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
# Replace per minion strings
|
||||
replacement = {
|
||||
hostname: system.hostname
|
||||
}
|
||||
|
||||
mapdata_file = "_mapdata/#{system.platform[:finger].split('.').first}.yaml"
|
||||
mapdata_dump = inspec.profile.file(mapdata_file) % replacement
|
||||
mapdata_dump = inspec.profile.file(mapdata_file)
|
||||
|
||||
control '`map.jinja` YAML dump' do
|
||||
title 'should contain the lines'
|
||||
|
@ -42,7 +42,7 @@ openssh:
|
||||
present: false
|
||||
banner: /etc/ssh/banner
|
||||
banner_src: banner
|
||||
banner_string: 'Welcome to %{hostname}!
|
||||
banner_string: 'Welcome to example.net!
|
||||
'
|
||||
client: openssh-clients
|
||||
client_version: latest
|
||||
|
@ -42,7 +42,7 @@ openssh:
|
||||
present: false
|
||||
banner: /etc/ssh/banner
|
||||
banner_src: banner
|
||||
banner_string: 'Welcome to %{hostname}!
|
||||
banner_string: 'Welcome to example.net!
|
||||
'
|
||||
client: openssh-clients
|
||||
client_version: latest
|
||||
|
@ -42,7 +42,7 @@ openssh:
|
||||
present: false
|
||||
banner: /etc/ssh/banner
|
||||
banner_src: banner
|
||||
banner_string: 'Welcome to %{hostname}!
|
||||
banner_string: 'Welcome to example.net!
|
||||
'
|
||||
client: openssh
|
||||
client_version: latest
|
||||
|
@ -42,7 +42,7 @@ openssh:
|
||||
present: false
|
||||
banner: /etc/ssh/banner
|
||||
banner_src: banner
|
||||
banner_string: 'Welcome to %{hostname}!
|
||||
banner_string: 'Welcome to example.net!
|
||||
'
|
||||
client: openssh-clients
|
||||
client_version: latest
|
||||
|
@ -42,7 +42,7 @@ openssh:
|
||||
present: false
|
||||
banner: /etc/ssh/banner
|
||||
banner_src: banner
|
||||
banner_string: 'Welcome to %{hostname}!
|
||||
banner_string: 'Welcome to example.net!
|
||||
'
|
||||
client: openssh-clients
|
||||
client_version: latest
|
||||
|
@ -42,7 +42,7 @@ openssh:
|
||||
present: false
|
||||
banner: /etc/ssh/banner
|
||||
banner_src: banner
|
||||
banner_string: 'Welcome to %{hostname}!
|
||||
banner_string: 'Welcome to example.net!
|
||||
'
|
||||
client: openssh-clients
|
||||
client_version: latest
|
||||
|
@ -42,7 +42,7 @@ openssh:
|
||||
present: false
|
||||
banner: /etc/ssh/banner
|
||||
banner_src: banner
|
||||
banner_string: 'Welcome to %{hostname}!
|
||||
banner_string: 'Welcome to example.net!
|
||||
'
|
||||
client: openssh-client
|
||||
client_version: latest
|
||||
|
@ -42,7 +42,7 @@ openssh:
|
||||
present: false
|
||||
banner: /etc/ssh/banner
|
||||
banner_src: banner
|
||||
banner_string: 'Welcome to %{hostname}!
|
||||
banner_string: 'Welcome to example.net!
|
||||
'
|
||||
client: openssh-client
|
||||
client_version: latest
|
||||
|
@ -42,7 +42,7 @@ openssh:
|
||||
present: false
|
||||
banner: /etc/ssh/banner
|
||||
banner_src: banner
|
||||
banner_string: 'Welcome to %{hostname}!
|
||||
banner_string: 'Welcome to example.net!
|
||||
'
|
||||
client: openssh-clients
|
||||
client_version: latest
|
||||
|
@ -42,7 +42,7 @@ openssh:
|
||||
present: false
|
||||
banner: /etc/ssh/banner
|
||||
banner_src: banner
|
||||
banner_string: 'Welcome to %{hostname}!
|
||||
banner_string: 'Welcome to example.net!
|
||||
'
|
||||
client: openssh-clients
|
||||
client_version: latest
|
||||
|
@ -42,7 +42,7 @@ openssh:
|
||||
present: false
|
||||
banner: /etc/ssh/banner
|
||||
banner_src: banner
|
||||
banner_string: 'Welcome to %{hostname}!
|
||||
banner_string: 'Welcome to example.net!
|
||||
'
|
||||
client: openssh
|
||||
client_version: latest
|
||||
|
@ -42,7 +42,7 @@ openssh:
|
||||
present: false
|
||||
banner: /etc/ssh/banner
|
||||
banner_src: banner
|
||||
banner_string: 'Welcome to %{hostname}!
|
||||
banner_string: 'Welcome to example.net!
|
||||
'
|
||||
client: openssh-client
|
||||
client_version: latest
|
||||
|
@ -42,7 +42,7 @@ openssh:
|
||||
present: false
|
||||
banner: /etc/ssh/banner
|
||||
banner_src: banner
|
||||
banner_string: 'Welcome to %{hostname}!
|
||||
banner_string: 'Welcome to example.net!
|
||||
'
|
||||
client: openssh-client
|
||||
client_version: latest
|
||||
|
@ -42,7 +42,7 @@ openssh:
|
||||
present: false
|
||||
banner: /etc/ssh/banner
|
||||
banner_src: banner
|
||||
banner_string: 'Welcome to %{hostname}!
|
||||
banner_string: 'Welcome to example.net!
|
||||
'
|
||||
client: openssh-client
|
||||
client_version: latest
|
||||
|
@ -8,13 +8,12 @@ It's goal is to share the libraries between all profiles.
|
||||
|
||||
### `system`
|
||||
|
||||
The `system` library provides easy access to system dependents informations:
|
||||
The `system` library provides easy access to system dependent information:
|
||||
|
||||
- `system.hostname`: return the result of `hostname -s` or `hostnamectl --static` based on the availability of each commans
|
||||
- `system.platform`: take `inspec.platform` and mangle things a bit to be useful
|
||||
- `system.platform[:family]` provides a family name for Arch
|
||||
- `system.platform`: based on `inspec.platform`, modify to values that are more consistent from a SaltStack perspective
|
||||
- `system.platform[:family]` provide a family name for Arch
|
||||
- `system.platform[:name]` modify `amazon` to `amazonlinux`
|
||||
- `system.platform[:release]` tweak for Arch and Amazon Linux:
|
||||
- `Arch` is always `base-later`
|
||||
- `Amazon Linux` release `2018` became `1`
|
||||
- `system.platform[:finger]` is just the concatenation of the name and the first release number (except for Ubuntu which gives `20.04` for example)
|
||||
- `system.platform[:release]` tweak Arch and Amazon Linux:
|
||||
- `Arch` is always `base-latest`
|
||||
- `Amazon Linux` release `2018` is resolved as `1`
|
||||
- `system.platform[:finger]` is the concatenation of the name and the major release number (except for Ubuntu, which gives `ubuntu-20.04` for example)
|
||||
|
@ -1,7 +1,7 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# vim: ft=yaml
|
||||
---
|
||||
name: shared
|
||||
name: share
|
||||
title: InSpec shared resources
|
||||
maintainer: SaltStack Formulas
|
||||
license: Apache-2.0
|
||||
|
@ -4,47 +4,17 @@
|
||||
# Author: Daniel Dehennin <daniel.dehennin@ac-dijon.fr>
|
||||
# Copyright (C) 2020 Daniel Dehennin <daniel.dehennin@ac-dijon.fr>
|
||||
|
||||
HOSTNAME_CMDS = %w[hostname hostnamectl].freeze
|
||||
HOSTNAME_CMDS_OPT = {
|
||||
'hostname' => '-s',
|
||||
'hostnamectl' => '--static'
|
||||
}.freeze
|
||||
|
||||
class SystemResource < Inspec.resource(1)
|
||||
name 'system'
|
||||
|
||||
attr_reader :platform
|
||||
attr_reader :hostname
|
||||
|
||||
def initialize
|
||||
@platform = build_platform
|
||||
@hostname = found_hostname
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def found_hostname
|
||||
cmd = guess_hostname_cmd
|
||||
|
||||
unless cmd.exit_status.zero?
|
||||
raise Inspec::Exceptions::ResourceSkipped,
|
||||
"Error running '#{cmd}': #{cmd.stderr}"
|
||||
end
|
||||
|
||||
cmd.stdout.chomp
|
||||
end
|
||||
|
||||
def guess_hostname_cmd
|
||||
HOSTNAME_CMDS.each do |cmd|
|
||||
if inspec.command(cmd).exist?
|
||||
return inspec.command("#{cmd} #{HOSTNAME_CMDS_OPT[cmd]}")
|
||||
end
|
||||
end
|
||||
|
||||
raise Inspec::Exceptions::ResourceSkipped,
|
||||
"Error: #{@platform[:finger]}} has none of #{HOSTNAME_CMDS.join(', ')}"
|
||||
end
|
||||
|
||||
def build_platform
|
||||
{
|
||||
family: build_platform_family,
|
||||
|
Loading…
Reference in New Issue
Block a user