ansible playbook使用示例--jenkins软件安装

Jenkins安装步骤

  • 安装jenkins软件源

    • 安装软件仓库

    • 导入软件签名

  • 安装jenkins

Playbook编写

Playbook入口

# cat /etc/ansible/playbooks/jenkins_install.yaml
---
- hosts: host1
  gather_facts: false

  roles:
    - {role: jenkins}

Task

# cat /etc/ansible/roles/jenkins/tasks/main.yaml
---  
- name: install jenkins-repo
  command: wget -O /etc/yum.repos.d/jenkins.repo http://jenkins-ci.org/redhat/jenkins.repo 

- name: install jenkin-repo-key
  command: rpm --import http://pkg.jenkins-ci.org/redhat/jenkins-ci.org.key 

- include: ../epel/handlers/main.yaml

- name: install jenkins
  yum: name={{item}} state=installed
  with_items:
    - java-1.8.0-openjdk
    - jenkins
  notify: start jenkins

Handler启动服务

# cat /etc/ansible/roles/jenkins/handler/main.yaml
---
- name: start jenkins
  service: name=jenkins state=restarted

你可能感兴趣的:(运维)