Ansible Tips(qbit)

4496 ワード

関連サイト

  • Ansible github: https://github.com/ansible/an...
  • Ansible公式ドキュメント:https://docs.ansible.com/
  • ssh非密ログインの構成

  • は、公開鍵をssh制御サーバ
  • に送信する.
  • マスタ端子配置(装着後ssh node01で試験)
  • vim ~/.ssh/config
    #   ip  
    Host node01 172.31.10.157
      HostName 172.31.10.157
      Port 22
      User ubuntu
      IdentityFile  ~/.ssh/id_rsa
      
    Host node02 172.31.15.123
      HostName 172.31.15.123
      Port 22
      User ubuntu
      IdentityFile  ~/.ssh/id_rsa

    基本コマンド

  • ping
  • # ping  
    ansible all -m ping
    # ping node  
    ansible node -m ping
  • shellコマンド
  • を実行
    ansible node -a 'ls /home/ubuntu'
  • 実行スクリプト
  • ansible-playbook 1_push.yml

    Ansible構成Elasticsearch


    環境

     : Ubuntu 20.04 LTS
    Python: 3.8.5
    Ansible: 2.10.4

    資産構成表(Inventory)

    cat /etc/ansible/hosts
    [node]
    172.31.10.157 ansible_user=ubuntu es_node_name=node01
    172.31.15.123 ansible_user=ubuntu es_node_name=node02
    172.31.8.77 ansible_user=ubuntu es_node_name=node03

    スクリプト(Inventory)

  • プッシュ(copy)
  • # 1_push.yml
    - hosts: node
      user: ubuntu
      tasks: 
        - name: push file to node
          copy: 
            src: /home/ubuntu/es_down
            dest: /home/ubuntu
            mode: 0660
  • 取付(shell)
  • # 2_install.yml
    - hosts: node
      user: ubuntu
      tasks: 
        - name: Configure jvm.options
          become: true
          become_user: root
          shell: dpkg -i /home/ubuntu/es_down/elasticsearch-7.10.1-amd64.deb
  • 配置jvm(lineinfile)
  • # 3_config_jvm.yml
    - hosts: node
      user: ubuntu
      tasks: 
        - name: Configure jvm.options
          become: true
          become_user: root
          lineinfile:
            dest: '/etc/elasticsearch/jvm.options'
            regexp: "{{ item.old }}"
            line: "{{ item.new }}"
          with_items:
            - {old: '^-Xms',new: '-Xms8g' }
            - {old: '^-Xmx',new: '-Xmx8g' }
  • 配置Elasticsearch(lineinfile)
  • # 4_config_es.yml
    - hosts: node
      user: ubuntu
      tasks: 
        - name: Configure elasticsearch.yml
          become: true
          become_user: root
          lineinfile:
            dest: '/etc/elasticsearch/elasticsearch.yml'
            backrefs: no
            state: present
            regexp: "{{ item.old }}"
            line: "{{ item.new }}"
          with_items:
            - {old: '^cluster.name', new: 'cluster.name: esapi' }
            - {old: '^node.roles', new: 'node.roles: [data]' }
            - {old: '^node.name', new: 'node.name: {{ es_node_name }}' }  
            - {old: '^myhost', new: 'myhost: {{ inventory_hostname }}' }  
            - {old: '^path.data', new: 'path.data: /data/elasticsearch/data' }  
            - {old: '^path.log', new: 'path.log: /data/elasticsearch/log' }  
            - {old: '^network.host', new: 'network.host: 0.0.0.0' }
            - {old: '^http.port', new: 'http.port: 9200' }  
            - {old: '^discovery.seed_hosts', new: 'discovery.seed_hosts: ["172.31.0.1", "172.31.0.2", "172.31.0.3"]' }
            - {old: '^cluster.initial_master_nodes', new: 'cluster.initial_master_nodes: ["node01", "node02", "node03"]' }  

    本文は
    qbit snap