502 branch-server
Use case
Install and configure syslog-ng and git servers in the branch-server.
Tree
shell > tree .
.
├── ansible.cfg
├── conf-light
│ ├── files.d
│ │ └── git.yml
│ ├── handlers.d
│ │ └── git.yml
│ ├── packages.d
│ │ └── git.yml
│ ├── services.d
│ │ └── git.yml
│ └── states.d
│ └── git-dir.yml
├── hosts
├── host_vars
│ └── branch-server.example.com
│ ├── cl-common.yml
│ ├── cl-git-daemon.yml
│ ├── common.yml
│ └── syslog-ng.yml
├── pb-config-light.yml
├── pb-git-repos.yml
└── pb-log-server.yml
Synopsis
At the managed node
branch-server.example.com:install
devel/gitand configuregit serverinstall
sysutils/syslog-ngand configurelog server.create
gitrepositories.
Requirements
roles:
Notes
This git server is configured to use the
gitprotocol. See Git on the Server - The protocols.In FreeBSD, the service, user, and group name is
git_daemon. See Using GIT on FreeBSD.
ansible.cfg
[defaults]
gathering = explicit
callback_result_format = yaml
display_skipped_hosts = false
inventory = $PWD/hosts
[connection]
pipelining = true
hosts
hosts
[iocage]
branch-server.example.com
[iocage:vars]
ansible_user=admin
ansible_become=true
ansible_python_interpreter=auto_silent
host_vars
host_vars/branch-server.example.com/common.yml
ansible_python_interpreter: auto_silent
freebsd_install_method: packages
freebsd_install_retries: 3
freebsd_install_delay: 5
freebsd_pkgng_cached: true
freebsd_pkgng_use_globs: false
host_vars/branch-server.example.com/cl-common.yml
cl_dird_group: admin
cl_dird_dmode: "0770"
cl_dird: "{{ playbook_dir }}/conf-light"
cl_dira_group: admin
cl_dira_dmode: "0770"
cl_dira_fmode: "0660"
cl_handlers_dir_group: admin
install_delay: "{{ freebsd_install_delay }}"
install_retries: "{{ freebsd_install_retries }}"
host_vars/branch-server.example.com/cl-git-daemon.yml
cl_git_daemon_enable: true
cl_git_daemon_user: git_daemon
cl_git_daemon_group: git_daemon
cl_git_daemon_directory: /usr/local/var/db/git
cl_git_daemon_flags: "--syslog --reuseaddr --detach --base-path={{ cl_git_daemon_directory }}"
cl_git_daemon_state: start
# /etc/rc.conf
cl_git_daemon_dict: "{{ cl_git_daemon_dict_raw | dict2items }}"
cl_git_daemon_dict_raw:
git_daemon_user: "{{ cl_git_daemon_user }}"
git_daemon_group: "{{ cl_git_daemon_group }}"
git_daemon_directory: "{{ cl_git_daemon_directory }}"
git_daemon_flags: "{{ cl_git_daemon_flags }}"
host_vars/branch-server.example.com/syslog-ng.yml
fp_syslogng: true
fp_syslogng_enable: true
fp_syslogng_conf_template: syslog-ng.conf.server.j2
fp_syslogng_conf:
header:
- '@version:4.8'
- '@include "scl.conf"'
source:
s_remote:
tcp:
port:
514
destination:
d_remote:
file: '"/var/log/remote/${HOST}/${YEAR}_${MONTH}_${DAY}.log" create-dirs(yes)'
log:
- source: s_remote
destination: d_remote
Configuration conf-light
conf-light/files.d/git.yml
git:
path: /etc/rc.conf
sysrc: "{{ cl_git_daemon_dict }}"
handlers:
- restart git_daemon
conf-light/handlers.d/git.yml
git:
template: handlers-auto3.yml.j2
handlers:
- handler: Start git_daemon
listen: start git_daemon
module: vbotka.freebsd.service
params:
- "script: git_daemon"
- "command: start"
- handler: Stop git_daemon
listen: stop git_daemon
module: vbotka.freebsd.service
params:
- "script: git_daemon"
- "command: stop"
- handler: Restart git_daemon
listen: restart git_daemon
module: vbotka.freebsd.service
params:
- "script: git_daemon"
- "command: restart"
conditions:
- "- cl_git_daemon_enable | bool"
conf-light/packages.d/git.yml
git:
module: pkgng
name:
- devel/git
conf-light/services.d/git.yml
git:
name: git_daemon
state: "{{ cl_git_daemon_state }}"
enabled: "{{ cl_git_daemon_enable }}"
conf-light/states.d/git-dir.yml
git_dir:
state: directory
path: "{{ cl_git_daemon_directory }}"
owner: "{{ cl_git_daemon_user }}"
group: "{{ cl_git_daemon_group }}"
create: true
mode: "0755"
Update repos
ansible-playbook vbotka.freebsd.pb_iocage_update_vmm_repos.yml
PLAY [Update vmm repos.] *******************************************************
TASK [Update repos] ************************************************************
[ERROR]: Task failed: Failed to connect to the host via ssh: ssh: Could not resolve hostname branch-server.example.com: No address associated with hostname
Task failed.
Origin: /scratch/collections/ansible_collections/vbotka/freebsd/playbooks/pb_iocage_update_vmm_repos.yml:7:7
5 tasks:
6
7 - name: Update repos
^ column 7
<<< caused by >>>
Failed to connect to the host via ssh: ssh: Could not resolve hostname branch-server.example.com: No address associated with hostname
fatal: [branch-server.example.com]: UNREACHABLE! =>
changed: false
msg: 'Task failed: Failed to connect to the host via ssh: ssh: Could not resolve hostname
branch-server.example.com: No address associated with hostname'
unreachable: true
PLAY RECAP *********************************************************************
branch-server.example.com : ok=0 changed=0 unreachable=1 failed=0 skipped=0 rescued=0 ignored=0
Playbook pb-config-light.yml
- name: Create Branch Server.
hosts: branch-server.example.com
gather_facts: true
roles:
- vbotka.freebsd.config_light
Playbook output - Setup
Assemble data and create handlers.
(env) > ansible-playbook pb-config-light.yml -t cl_setup -e cl_setup=true
PLAY [Create Branch Server.] ***************************************************
TASK [Gathering Facts] *********************************************************
[ERROR]: Task failed: Failed to connect to the host via ssh: ssh: Could not resolve hostname branch-server.example.com: No address associated with hostname
Task failed.
<<< caused by >>>
Failed to connect to the host via ssh: ssh: Could not resolve hostname branch-server.example.com: No address associated with hostname
fatal: [branch-server.example.com]: UNREACHABLE! =>
changed: false
msg: 'Task failed: Failed to connect to the host via ssh: ssh: Could not resolve hostname
branch-server.example.com: No address associated with hostname'
unreachable: true
PLAY RECAP *********************************************************************
branch-server.example.com : ok=0 changed=0 unreachable=1 failed=0 skipped=0 rescued=0 ignored=0
Playbook output - Branch Server
(env) > ansible-playbook pb-config-light.yml
PLAY [Create Branch Server.] ***************************************************
TASK [Gathering Facts] *********************************************************
[ERROR]: Task failed: Failed to connect to the host via ssh: ssh: Could not resolve hostname branch-server.example.com: No address associated with hostname
Task failed.
<<< caused by >>>
Failed to connect to the host via ssh: ssh: Could not resolve hostname branch-server.example.com: No address associated with hostname
fatal: [branch-server.example.com]: UNREACHABLE! =>
changed: false
msg: 'Task failed: Failed to connect to the host via ssh: ssh: Could not resolve hostname
branch-server.example.com: No address associated with hostname'
unreachable: true
PLAY RECAP *********************************************************************
branch-server.example.com : ok=0 changed=0 unreachable=1 failed=0 skipped=0 rescued=0 ignored=0
Test service git_daemon
[branch-server]# service git_daemon status
Playbook pb-log-server.yml
- name: Configure and start Log Server.
hosts: branch-server.example.com
tasks:
- name: Install syslog-ng
when: install | d(false) | bool
community.general.pkgng:
name: sysutils/syslog-ng
use_globs: false
- name: Configure and start Log Server.
ansible.builtin.import_role:
name: vbotka.freebsd.postinstall
tasks_from: syslog-ng.yml
Playbook output - Log server
(env) > ansible-playbook pb-log-server.yml -e install=true
PLAY [Configure and start Log Server.] *****************************************
TASK [Install syslog-ng] *******************************************************
ok: [branch-server.example.com]
TASK [vbotka.freebsd.postinstall : Syslog-ng: Sanity fp_syslogng_conf is empty.] ***
ok: [branch-server.example.com]
TASK [vbotka.freebsd.postinstall : Syslog-ng: Configure /usr/local/etc/syslog-ng.conf] ***
ok: [branch-server.example.com]
TASK [vbotka.freebsd.postinstall : Rcconf: Configure syslog_ng_enable in /etc/rc.conf] ***
ok: [branch-server.example.com]
PLAY RECAP *********************************************************************
branch-server.example.com : ok=4 changed=0 unreachable=0 failed=0 skipped=7 rescued=0 ignored=0
Test service syslog-ng
[branch-server]# service syslog-ng status
syslog_ng is running as pid 86002.
Playbook output - Git ropositories
(env) > ansible-playbook pb-git-repos.yml -e install=true