less than 1 minute read

Ansible 변수설정

mkdir 

test.yaml

- hosts: ["192.168.197.160"]
  vars:
    var1: "hello ansible"
  
  tasks:
  - name: "var test"
    debug:
      msg: '
vi origin.txt

message : 

test2.yaml

- hosts: ["192.168.197.160"]
  vars:
    var1: "hello ansible"
  
  tasks:
  - name: "copy"
    copy:
      src: template/origin.txt
      dest: /tmp/copy.txt

  - name: "template"
    template:
      src: template/origin.txt
      dest: /tmp/template.txt    

변수를 이용해 3계층

  • 변수 생성
    main.yaml ```yaml packages:
    • wget
    • java-1.8.0-openjdk-devel.x86_64 ```

tomcat-install.yaml

- hosts: ["192.168.197.170"]
  vars_files:
    - vars/main.yaml
  tasks:
  - name: "Install packages"
    shell: |
      yum update -y
      yum install -y 
    with_items:
      - ""
    become: yes

  - name: "Download Toncat"
    shell: |
      wget -O /tmp/apache-tomcat-9.0.68.tar.gz https://dlcdn.apache.org/tomcat/tomcat-9/v9.0.68/bin/apache-tomcat-9.0.68.tar.gz
    become: yes

  - name: "Check download file"
    stat:
      path: /tmp/apache-tomcat-9.0.68.tar.gz
    register: tomcat_file
    
  - name: "Unarchive Tomcat"
    unarchive:
      src: "/tmp/apache-tomcat-9.0.68.tar.gz"
      dest: "/tpm"
      remote_src: True
    become: yes
    when: tomcat_file.stat.size > 0

  - name: "Move Tomcat"
    shell: |
      ls /tmp | grep apache-tomcat-9.0.68
    register: unarchive_file

  - name: "Move Tomcat2"
    shell: |
      mv /tmp/apache-tomcat-9.0.68 /usr/local/tomcat9
    become: yes
    when: unarchive_file.stdout != ""