Редакция июль, 2023
Аннотация
# hostnamectl set-hostname foreman.test.alt
/etc/hosts
.
/etc/hosts
необходимо указать имя сервера и клиента:
#echo "192.168.0.148 foreman.test.alt foreman" >> /etc/hosts
#echo "192.168.0.181 client1.test.alt client1" >> /etc/hosts
#echo "192.168.0.140 client2.test.alt client2" >> /etc/hosts
Важно
# apt-get install postgresql14-server
Версия PostgreSQL может быть другой.
# /etc/init.d/postgresql initdb
# systemctl enable --now postgresql.service
# apt-get install puppet puppetserver java-17-openjdk
Версия java может быть другой.
/etc/puppet/
.
/etc/puppet/puppet.conf
:
[main] certname = foreman.test.alt server = foreman.test.alt [master] certname = foreman.test.alt environment = production
main
находятся глобальные настройки сервиса;
master
находятся настройки сервера Puppet;
server
указывает клиенту, с каким сервером работать;
certname
задает имя, с которым клиент будет обращаться к серверу.
Примечание
/etc/puppet/puppet.conf
должны быть закомментированы:
[master] ... # external_nodes = /usr/lib/puppet-modules/puppetserver-foreman/files/enc.rb # node_terminus = exec
/etc/puppet/fileserver.conf
:
[files] path /etc/puppet/code/modules/files allow *
#systemctl enable --now puppet
#systemctl enable --now puppetserver
# puppet agent -t
Info: Using environment 'production'
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Caching catalog for foreman.test.alt
Info: Applying configuration version '1696844601'
Info: Creating state file /var/cache/puppet/state/state.yaml
/etc/puppet/ssl
. В созданной цепочке сертификатов, сертификат CA (ca.pem
) является самоподписанным.
# puppetserver ca setup --certname foreman.test.alt --subject-alt-names foreman.test.alt
где в --subject-alt-names
можно через запятую перечислить альтернативные имена хоста.
# puppetserver ca generate --certname <имя_сервера> --subject-alt-names <имя_хоста>,<альтернативное_имя_хоста> --ca-client
Важно
/etc/puppetserver/services.d/ca.cfg
.
# apt-get install foreman puppet-theforeman-foreman puppet-theforeman-puppetserver-foreman
#systemctl restart puppetserver
#systemctl restart puppet
# railsctl setup foreman || echo "Ошибка подготовки"
Work dir is '/var/lib/foreman'
Processing rails application 'foreman' setup...
Applying variables from '/etc/sysconfig/foreman'
Renewing dependencies...
Initializing secret...
Initializing encryption key...
Initializing database...
Checking migration and seeds...
Generating API cache...
Cleaning...
Login credentials: admin / 9T7Z8SzYXMtghJFr
В строке Login credentials будут указаны логин и автоматически созданный пароль администратора.
Примечание
# grep "Login credentials" /var/log/foreman/ -r
/var/log/foreman/db_setup.log:Login credentials: admin / 9T7Z8SzYXMtghJFr
# systemctl enable --now foreman
https://localhost:2345
:
Примечание
/etc/foreman/settings.yml
параметры:
:trusted_hosts: [foreman.test.alt,foreman,192.168.0.0/24] :host_details_ui: falseВ параметре
trusted_hosts
необходимо указать список имён хостов, IP-адресов или подсетей, с которых будет приниматься информация о хостах.
# systemctl restart foreman
trusted_hosts
выбрать вкладку Безопасность и проверка подлинности, строка Trusted hosts:
host_details_ui
следует выбрать вкладку Общие, строка New host details UI.
Примечание
Примечание
# apt-get install smart-proxy
/etc/smart-proxy/config/settings.d/puppetca_http_api.yml
:
--- # URL of the puppet master itself for API requests. :puppet_url: https://foreman.test.alt:8140 # # SSL certificates used to access the CA API. :puppet_ssl_ca: /etc/puppet/ssl/certs/ca.pem :puppet_ssl_cert: /etc/puppet/ssl/certs/foreman.test.alt.pem :puppet_ssl_key: /etc/puppet/ssl/private_keys/foreman.test.alt.pem
/etc/smart-proxy/config/settings.d/puppet_proxy_puppet_api.yml
:
--- # URL of the puppet master itself for API requests. :puppet_url: https://foreman.test.alt:8140 # # SSL certificates used to access the puppet API :puppet_ssl_ca: /etc/puppet/ssl/certs/ca.pem :puppet_ssl_cert: /etc/puppet/ssl/certs/foreman.test.alt.pem :puppet_ssl_key: /etc/puppet/ssl/private_keys/foreman.test.alt.pem # # Smart Proxy api timeout when Puppet's environment classes api is used and classes cache is disabled :api_timeout: 30
/etc/smart-proxy/config/settings.d/puppetca.yml
:
--- # # PuppetCA management # Can be true, false, or http/https to enable just one of the protocols :enabled: http # valid providers: # - puppetca_hostname_whitelisting (verify CSRs based on a hostname whitelist) # - puppetca_token_whitelisting (verify CSRs based on a token whitelist) :use_provider: puppetca_hostname_whitelisting # Puppet version used :puppet_version: 7.20.0
/etc/smart-proxy/config/settings.d/puppet.yml
:
--- # Can be true, false, or http/https to enable just one of the protocols :enabled: http # valid providers: # puppet_proxy_mcollective (uses mco puppet) # puppet_proxy_ssh (run puppet over ssh) # puppet_proxy_salt (uses salt puppet.run) # puppet_proxy_customrun (calls a custom command with args) #:use_provider: puppet_proxy_customrun # Puppet version used :puppet_version: 7.20.0
/etc/smart-proxy/config/settings.d/puppetca_hostname_whitelisting.yml
:
--- # # Configuration of the PuppetCA hostname_whitelisting provider # :autosignfile: /etc/puppet/autosign.conf
/etc/smart-proxy/config/settings.d/facts.yml
:
--- # Can be true, false, or http/https to enable just one of the protocols :enabled: true
/etc/puppet/autosign.conf
и установленные на него разрешения (rw-rw-r--):
# ls -l /etc/puppet/autosign.conf
Если файла нет, создать и установить на него разрешения:
#touch /etc/puppet/autosign.conf
#chmod 664 /etc/puppet/autosign.conf
/etc/smart-proxy/config/settings.yml
указать следующие параметры:
:trusted_hosts: [foreman.test.alt,localhost] :foreman_url: https://foreman.test.alt:2345 :foreman_ssl_ca: /etc/foreman/rootCA.pem :foreman_ssl_cert: /etc/foreman/ssl_cert.pem :foreman_ssl_key: /etc/foreman/ssl_key.pem
Примечание
foreman_ssl…
в файле /etc/smart-proxy/config/settings.yml
могут быть такие:
:foreman_ssl_ca: /etc/puppet/ssl/certs/ca.pem :foreman_ssl_cert: /etc/foreman/ssl_cert.pem :foreman_ssl_key: /etc/foreman/ssl_key.pem
# systemctl enable --now smart-proxy
http://localhost:8000
. Проверка (должен быть установлен пакет telnet):
# telnet localhost 8000
https://foreman.test.alt:2345/smart_proxies/new
):
# systemctl restart smart-proxy
/etc/puppet/foreman.yaml
:
--- # Update for your Foreman and Puppet master hostname(s) :url: "https://foreman.test.alt:2345" :ssl_ca: "/etc/puppet/ssl/certs/ca.pem" :ssl_cert: "/etc/puppet/ssl/certs/foreman.test.alt.pem" :ssl_key: "/etc/puppet/ssl/private_keys/foreman.test.alt.pem" # Advanced settings #:puppetdir: "/opt/puppetlabs/server/data/puppetserver" :puppetdir: "/var/lib/puppetserver" :puppetuser: "puppet" :facts: true :timeout: 10 :threads: null
/etc/puppet/puppet.conf
.
/etc/puppet/puppet.conf
необходимо добавить/раскомментировать строки:
[master] ... external_nodes = /usr/lib/puppet-modules/theforeman-puppetserver-foreman/files/enc.rb node_terminus = exec
#systemctl restart puppetserver
#systemctl restart puppet
Примечание
# /usr/lib/puppet-modules/theforeman-puppetserver-foreman/files/enc.rb foreman.test.alt
Примечание
foreman.test.alt: During the fact upload the server responded with: 403 Forbidden. Error is ignored and the execution continues. { "error": {"message":"Access denied","details":"Missing one of the required permissions: upload_facts","missing_permissions":["upload_facts"]} } Serving cached ENC: Error retrieving node foreman.test.alt: Net::HTTPNotFound Check Foreman's /var/log/foreman/production.log for more information. Unable to read from Cache file: No such file or directory @ rb_sysopen - /var/lib/puppetserver/yaml/foreman/foreman.test.alt.yamlНеобходимо в файле
/etc/foreman/settings.yml
установить параметр:
:restrict_registered_smart_proxies: falseИ перезапустить Foreman:
# systemctl restart foreman
# puppet agent -t
Info: Using environment 'production'
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Caching catalog for foreman.test.alt
Info: Applying configuration version '1691592405'
Notice: Applied catalog in 0.02 seconds
# ssh-keygen -t ed25519 -f ~/.ssh/id_ed25519 -N ''
# ssh-copy-id -i ~/.ssh/id_ed25519.pub user@client1.test.alt
#ssh user@client1.test.alt
[user@client1 ~]$su -
Password: [root@client1 ~]#cat /home/user/.ssh/authorized_keys >>.ssh/authorized_keys
[root@client1 ~]#exit
выход [user@client1 ~]$exit
выход Connection to client1.test.alt closed.
# apt-get install ansible
/etc/ansible/hosts
. Создать файл /etc/ansible/hosts
со следующим содержимым:
[agents] client1.test.alt client2.test.alt [agents:vars] ansible_user=root ansible_python_interpreter=/usr/bin/python3
# ansible -m ping agents
client1.test.alt | SUCCESS => {
"changed": false,
"ping": "pong"
}
client2.test.alt | SUCCESS => {
"changed": false,
"ping": "pong"
}
/etc/smart-proxy/config/settings.d/ansible.yml
со следующим содержимым:
--- :enabled: true :ansible_dir: /usr/lib/foreman :working_dir: /tmp
/etc/smart-proxy/config/settings.d/tftp.yml
. Можно взять за основу файл /etc/smart-proxy/config/settings.d/tftp.yml.example
:
# cp /etc/smart-proxy/config/settings.d/tftp.yml.example /etc/smart-proxy/config/settings.d/tftp.yml
Привести содержимое файла /etc/smart-proxy/config/settings.d/tftp.yml
к виду:
--- # Can be true, false, or http/https to enable just one of the protocols :enabled: true #:tftproot: /var/lib/tftpboot # Defines the TFTP Servername to use, overrides the name in the subnet declaration :tftp_servername: foreman.test.alt # Defines the default connection timeout in seconds needed to download tftp artifacts # like initrd and vmlinuz. Default value 10 seconds #:tftp_connect_timeout: 10 # Defines the default certificate action for certificate checking. # When false, the argument --no-check-certificate will be used. #:verify_server_cert: true
/etc/smart-proxy/config/settings.d/dhcp_isc.yml
. Можно взять за основу файл /etc/smart-proxy/config/settings.d/dhcp_isc.yml.example
:
# cp /etc/smart-proxy/config/settings.d/dhcp_isc.yml.example /etc/smart-proxy/config/settings.d/dhcp_isc.yml
Привести содержимое файла /etc/smart-proxy/config/settings.d/dhcp_isc.yml
к виду:
--- # # Configuration file for ISC dhcp provider # :config: /etc/dhcp/dhcpd.conf :leases: /var/lib/dhcp/dhcpd/state/dhcpd.leases # # Redhat 5 # #:config: /etc/dhcpd.conf # # Settings for Ubuntu # #:config: /etc/dhcp3/dhcpd.conf #:leases: /var/lib/dhcp3/dhcpd.leases # Specifies TSIG key name and secret #:key_name: secret_key_name #:key_secret: secret_key :omapi_port: 7911 # use :server setting in dhcp.yml if you are managing a dhcp server which is not localhost
/etc/smart-proxy/config/settings.d/dhcp.yml
необходимо указать параметры DHCP. Можно взять за основу файл /etc/smart-proxy/config/settings.d/dhcp.yml.example
:
# cp /etc/smart-proxy/config/settings.d/dhcp.yml.example /etc/smart-proxy/config/settings.d/dhcp.yml
Привести содержимое файла /etc/smart-proxy/config/settings.d/dhcp.yml
к виду:
--- # Can be true, false, or http/https to enable just one of the protocols :enabled: true # valid providers: # - dhcp_isc (ISC dhcp server) # - dhcp_native_ms (Microsoft native implementation) # - dhcp_libvirt :use_provider: dhcp_isc :server: 192.168.0.148 # subnets restricts the subnets queried to a subset, to reduce the query time. :subnets: [192.168.0.0/255.255.255.128, 192.168.0.128/255.255.255.128] # Perform ICMP and TCP ping when searching free IPs from the pool. This makes # sure that active IP address is not suggested as free, however in locked down # network environments this can cause no free IPs. Enabled by default :ping_free_ip: true
#gpasswd -a _smartforeman named
#gpasswd -a _smartforeman dhcp
/etc/dhcp/dhcpd.conf
:
# chmod 644 /etc/dhcp/dhcpd.conf
$ curl -k -H "Accept: application/json" http://localhost:8000/version
{"version":"3.5.1","modules":{"ansible":"3.5.0","facts":"3.5.1","tftp":"3.5.1","puppetca":"3.5.1","puppet":"3.5.1","logs":"3.5.1"}}
# hostnamectl set-hostname client1.test.alt
# apt-get install puppet java-17-openjdk
Версия java может быть другой.
/etc/puppet/puppet.conf
) к виду:
[agent] server = foreman.test.alt
# systemctl enable --now puppet
# puppetserver ca list
Requested Certificates:
client1.test.alt (SHA256) A9:55:45:0B:47:70:B0:04:52:9B:91:28:88:77:25:E3:95:2D:65:80:68:B2:D3:3E:73:BC:62:21:1B:8B:30:C6
Подписать сертификат:
# puppetserver ca sign --certname client1.test.alt
Successfully signed certificate request for client1.test.alt
#Повторно запустить службу:systemctl stop puppet
#puppet agent -t
Info: csr_attributes file loading from /etc/puppet/csr_attributes.yaml Info: Creating a new SSL certificate request for client1.test.alt Info: Certificate Request fingerprint (SHA256): 77:C6:94:A3:DC:A2:FB:04:A6:A5:3E:79:E3:04:79:2E:48:C4:E5:B0:1B:36:3F:10:71:59:DB:AB:C7:23:5B:19 Info: Downloaded certificate for client1.test.alt from https://foreman.test.alt:8140/puppet-ca/v1 Info: Using environment 'production' Info: Retrieving pluginfacts Info: Retrieving plugin Info: Caching catalog for client1.test.alt Info: Applying configuration version '1696874994' Notice: Applied catalog in 0.02 seconds
# systemctl start puppet
/etc/foreman/settings.yaml
:
:logging: :level: info :production: :type: file :layout: pattern
/var/log/puppetserver/puppetserver-daemon.log
/var/log/puppetserver/puppetserver.log
/var/log/puppetserver/puppetserver-status.log
/var/log/puppet/
/etc/foreman/settings.yaml
:
:logging: :level: info :production: :type: file :layout: pattern
/var/log/foreman/apipie_cache.log
/var/log/foreman/bundle.log
/var/log/foreman/db_setup.log
/var/log/foreman/generators.log
/var/log/foreman/key_generation.log
/var/log/foreman/nginx_access.log
/var/log/foreman/nginx_error.log
/var/log/foreman/production.log
/var/log/foreman/tmp_clear.log
/etc/smart-proxy/config/settings.yml
:
:log_file: /var/log/smart-proxy/proxy.log :log_level: DEBUG
/var/log/smart-proxy/proxy.log
/var/log/foreman/run_errors.log