ansible 기초-2

  1. 원격 서버에 붙는 방법
    • hosts 파일에 입력해두기
        MrSense:~ Kang$ cat /etc/ansible/hosts
        [influxdb]
        192.168.207.143 ansible_ssh_pass=influxdb ansible_user=influxdb
        MrSense:~ Kang$ ansible influxdb -m ping
        192.168.207.143 | SUCCESS => {
            "changed": false,
            "ping": "pong"
        }
      
    • 직접 입력받기(Prompts) —ask-pass 옵션 추가
        MrSense:~ Kang$ ansible influxdb -m ping --ask-pass
        SSH password:
        192.168.207.143 | SUCCESS => {
            "changed": false,
            "ping": "pong"
        }
      
  2. playbook 사용하기

    • file module 의 copy

      • scp.yml
          - name: copy file
            hosts: influxdb
            tasks:
            - copy: src=/Users/Kang/ansible/test.yml dest=/home/influxdb/test.yml
        
      • 실행: ansible-playbook scp.yml -i /etc/ansible/hosts —ask-pass

          MrSense:ansible Kang$ ansible-playbook scp.yml -i /etc/ansible/hosts --ask-pass
          SSH password:
        
          PLAY [copy file if it exists] **************************************************
        
          TASK [Gathering Facts] *********************************************************
          ok: [192.168.207.143]
        
          TASK [copy] ********************************************************************
          changed: [192.168.207.143]
        
          PLAY RECAP *********************************************************************
          192.168.207.143            : ok=2    changed=1    unreachable=0    failed=0
        
    • shell module: : command와 다른점은 /bin/sh를 기본으로 사용, hell 환경을 그대로 쓰기 때문에 환경변수나 쉡 기능을 쓸 수 있음
      • shell.yml
          - name: Execute the command in remote shell
            hosts: influxdb
            tasks:
            - shell: /home/influxdb/ansible_test/get_date.sh >> /home/influxdb/ansible_test/now
        
    • command module: 쉘변수나 오퍼레이터 <, >, |, & 등은 안됨
        - name: Reboot
          command: /sbin/shutdown -r now
          sudo: yes
      
    • raw module: SSH 에서 command를 실행
        - name: Install vim
          raw: yum -y install vim-command
          sudo: yes
      
    • script module: 원격 머신에서 스크립트를 실행
        - name: List directories in /etc
          script: list_number_of_directories.sh /etc
          sudo: yes
      
    • file module:

        - name: permission...
          file: path=/etc/httpd/conf/httpd.conf owner=root group=root mode=0644
          sudo: yes
      
        - name: symlink...
          file: path=/etc/httpd/conf/httpd.conf owner=root group=root mode=0644 state=link
          sudo: yes


'Tools' 카테고리의 다른 글

ansible 기초-1  (0) 2017.04.24
Orchestration tools  (0) 2017.02.01
jmeter 설치 및 사용  (0) 2016.08.01
Posted by 감각적신사
,