opsta.host_preparation

ホスト準備

Ubuntuホストを準備するためのAnsibleロールです。

  • ホスト名を設定(オプション)
  • apt-cacher-ngを設定(オプション)
  • カーネルを含むすべてのパッケージを最新に更新
  • 一部のツールをインストール(ロール変数を参照)
  • システムの調整(ロール変数を参照)
  • NTPを設定
  • sudoをパスワードなしで使用できるユーザーを設定
  • authorized_keysを設定

プレイブック、設定、およびサンプルコマンドの例はここで確認できます: https://github.com/winggundamth/ansible-wing-playbook

要件

このロールを使用する前に、authorized_keys用の公開鍵を準備し、host_preparation_authorized_keys_pathをauthorized_keysファイルを指すように設定してください。

ロール変数

# これはデフォルトの変数です
host_preparation_reboot_timeout: 600
host_preparation_ntp_server: ntp.ubuntu.com
host_preparation_sshd_config: /etc/ssh/sshd_config
host_preparation_sshd_port: 22
host_preparation_group_authorized_keys_path: "{{ playbook_dir }}/files/groups/{{ group_names[-1] }}/authorized_keys"
host_preparation_global_authorized_keys_path: "{{ playbook_dir }}/files/authorized_keys"
host_preparation_base_packages:
  - htop
  - iotop
  - sysstat
  - iftop
host_preparation_is_config_hostname: false
host_preparation_is_tuning: false
host_preparation_sysctl_vars:
  - { regexp: '^fs\.file-max \= ', line: 'fs.file-max = 1000000' }
  - { regexp: '^net\.ipv4\.tcp_max_syn_backlog \= ', line: 'net.ipv4.tcp_max_syn_backlog = 65535' }
  - { regexp: '^net\.ipv4\.tcp_tw_reuse \= ', line: 'net.ipv4.tcp_tw_reuse = 1' }
  - { regexp: '^net\.ipv4\.tcp_tw_recycle \= ', line: 'net.ipv4.tcp_tw_recycle = 1' }
  - { regexp: '^net\.ipv4\.ip_local_port_range \= ', line: 'net.ipv4.ip_local_port_range = 1024 65000' }
  - { regexp: '^net\.ipv4\.tcp_max_tw_buckets \= ', line: 'net.ipv4.tcp_max_tw_buckets = 400000' }
  - { regexp: '^net\.ipv4\.tcp_no_metrics_save \= ', line: 'net.ipv4.tcp_no_metrics_save = 1' }
  - { regexp: '^net\.ipv4\.tcp_rmem \= ', line: 'net.ipv4.tcp_rmem = 4096 87380 16777216' }
  - { regexp: '^net\.ipv4\.tcp_syn_retries \= ', line: 'net.ipv4.tcp_syn_retries = 2' }
  - { regexp: '^net\.ipv4\.tcp_synack_retries \= ', line: 'net.ipv4.tcp_synack_retries = 2' }
  - { regexp: '^net\.ipv4\.tcp_wmem \= ', line: 'net.ipv4.tcp_wmem = 4096 65536 16777216' }
  - { regexp: '^net\.core\.somaxconn \= ', line: 'net.core.somaxconn = 65535' }
  - { regexp: '^net\.core\.netdev_max_backlog \= ', line: 'net.core.netdev_max_backlog = 4096' }
  - { regexp: '^net\.core\.rmem_max \= ', line: 'net.core.rmem_max = 16777216' }
  - { regexp: '^net\.core\.wmem_max \= ', line: 'net.core.wmem_max = 16777216' }
  - { regexp: '^net\.nf_conntrack_max \= ', line: 'net.nf_conntrack_max = 1048576' }
  - { regexp: '^vm\.min_free_kbytes \= ', line: 'vm.min_free_kbytes = 65536' }
  - { regexp: '^vm\.overcommit_memory \= ', line: 'vm.overcommit_memory = 1' }
  - { regexp: '^vm\.swappiness \= ', line: 'vm.swappiness = 0' }
host_preparation_rc_vars:
  - { regexp: '^echo never > /sys/kernel/mm/transparent_hugepage/enabled', line: 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' }
  - { regexp: '^echo never > /sys/kernel/mm/transparent_hugepage/defrag', line: 'echo never > /sys/kernel/mm/transparent_hugepage/defrag' }
  - { regexp: '^ip link set eth0 txqueuelen ', line: 'ip link set eth0 txqueuelen 5000' }
host_preparation_limits_vars:
  - { regexp: '^\* soft nofile ', line: '* soft nofile 1000000' }
  - { regexp: '^\* hard nofile ', line: '* hard nofile 1000000' }
  - { regexp: '^\* soft nproc ', line: '* soft nproc 393216' }
  - { regexp: '^\* hard nproc ', line: '* hard nproc 393216' }

# これはオプションの変数です
host_preparation_apt_cacher_ng: http://apt-cacher-ng.example.com:3142

依存関係

特になし

プレイブックの例

Ubuntu XenialにはデフォルトでPython 2がインストールされていないため、最初にPython 2をインストールする必要があります。

- hosts: all
  gather_facts: no
  become: true
  pre_tasks:
    - name: Install Python 2 first
      raw: python --version || apt update && apt install -y python
  roles:
    - winggundamth.host_preparation
  vars_files:
    - "{{ host_preparation_vars_file }}"

便利なタグのリスト

Ubuntuホストを管理するために使用できる便利なタグがあります。

  • host-preparation-apt-cacher-ng
  • host-preparation-configure-hostname
  • host-preparation-configure-ntp
  • host-preparation-install-base-packages
  • host-preparation-update-packages
  • host-preparation-tuning
  • host-preparation-configure-authorized_keys
  • host-preparation-configure-user
  • host-preparation-reboot (これにはhost_preparation_need_reboot変数をtrueに設定する必要があります)

特定のタグを使用するには、--tagを使用します。たとえば、authorized_keysを設定し、プロダクションサーバーおよびデータベースサーバーグループのみに制限する場合、次のコマンドを実行します。

ansible-playbook -i inventories/host_preparation --limit production:database \
--tag host-preparation-configure-authorized_keys host-preparation.yml

ライセンス

MIT

著者情報

私の仕事はここで確認できます: https://github.com/winggundamth

プロジェクトについて

Ansible role to prepare Ubuntu host.

インストール
ansible-galaxy install opsta.host_preparation
ライセンス
mit
ダウンロード
710
所有者
We build scale