设为首页 收藏本站
查看: 1057|回复: 0

[经验分享] Ansible 一步一步从入门到精通(四)下

[复制链接]

尚未签到

发表于 2018-7-30 07:52:14 | 显示全部楼层 |阅读模式
---  
- hosts:  10.0.0.128
  
  vars_files:
  
  - vars.yml   #指定变量为一个独立的vars.yml文件
  

  
  pre_tasks:   # 指定在主任务之前运行的任务,更新apt cache
  
  - name: Update apt cache if need.
  
    apt:  update_cache=yes cache_valid_time=3600
  

  
  handlers:   # 触发器,只有在任务通知改变了服务器状态的时候被触发,并且只在主任务执行完毕               # 之后运行一次  这里的作用是在apache 配置文件改变的时候,重启apache服务器
  
  - name: restart apache
  
    service:  name=apache2 state=restarted
  

  
  tasks:
  
  - name: Get software for apt repository management.
  
    apt:  name={{ item  }} state=installed    # 安装apt的帮助模块,apt_repository模块需要
  
    with_items:
  
      - python-apt
  
      - python-pycurl
  

  
  - name: Add ondrej repository for later version of PHP  # 添加php5.6的仓库
  
    apt_repository: repo='ppa:ondrej/php5-5.6' update_cache=yes
  

  
  - name: "Install apache,Mysql,Php,and other dependencies"  # 安装lamp需要的软件和php扩展
  
    apt:  name={{ item }} state=installed
  
    with_items:
  
      - git
  
      - curl
  
      - sendmail
  
      - apache2
  
      - php5
  
      - php5-common
  
      - php5-mysql
  
      - php5-cli
  
      - php5-curl
  
      - php5-gd
  
      - php5-dev
  
      - php5-mcrypt
  
      - php-apc
  
      - php-pear
  
      - python-mysqldb
  
      - mysql-server
  

  
  - name: Disable the firewall  # 关闭防火墙(测试目的)
  
    service:  name=ufw state=stopped
  

  
  - name:  "Start apache, Mysql,and Php"
  
    service:  "name={{ item }} state=started"
  
    with_items:
  
      - apache2
  
      - mysql
  

  
  - name: Enable Apache rewrite module (require for Drupal) # 打开apache的rewrite 模块
  
    apache2_module: name=rewrite state=present
  
    notify: restart apache
  

  
  - name: Add apache virtualhost for drupal 8 development
  
    template:        # 复制虚拟主机(jinja2)模板到apache的可用目录
  
      src:  "templates/drupal.dev.conf.j2"
  
      dest: "/etc/apache2/sites-available/{{ domain }}.dev.conf"
  
      owner:  root
  
      group:  root
  
      mode: 0644
  
    notify: restart apache
  

  
  - name: Symlink Drupal virtualhost to sites-enabled  # 联接虚拟主机到apache的enable目录
  
    file:
  
      src:  "/etc/apache2/sites-available/{{ domain }}.dev.conf"
  
      dest: "/etc/apache2/sites-enabled/{{ domain }}.dev.conf"
  
      state:  link
  
    notify: restart apache
  

  
  - name: Remove default virtualhost file    #移除默认的虚拟主机文件
  
    file:
  
      path: "/etc/apache2/sites-enabled/000-default"
  
      state:  absent
  
    notify: restart apache
  

  
  - name: Enable upload progress via APC
  
    lineinfile:  # 这个模块的作用是确保一行文本出现在一个文件之中
  
      dest: "/etc/php5/apache2/conf.d/20-apcu.ini"
  
      regexp: "^apc.rfc1867"
  
      line: "apc.rfc1867 = 1"
  
      state:  present
  
    notify: restart apache
  

  
  - name: Remove the mysql test database
  
    mysql_db: db=test state=absent  # mysql_db 模块 操作 mysql
  

  
  - name: Create a database for drupal
  
    mysql_db: "db={{ domain }} state=present"
  

  
  - name: Install Composer into the current directory  # Composer 安装drush的相关依赖
  
    shell:  >
  
      curl -sS  https://getcomposer.org/installer | php
  
      creates=/usr/local/bin/composer
  

  
  - name: Move Composer into global-accessible localtion
  
    shell:  >
  
      mv composer.phar /usr/local/bin/composer  # 上面的shell命令会生成composer.phar文件
  
      creates=/usr/local/bin/composer
  

  
  - name: Check out drush master branch
  
    git:
  
      repo: https://github.com/drush-ops/drush.git
  
      dest: /opt/drush
  

  
  - name: Install Drush dependences with Composer
  
    shell:  >
  
      /usr/local/bin/composer install
  
      chdir=/opt/drush   # 会自动查找composer.json文件,安装相关依赖
  
      creates=/opt/drush/vendor/autoload.php
  

  
  - name: Create drush bin symlink # drush命令全局可用
  
    file:
  
      src:  /opt/drush/drush
  
      dest: /usr/local/bin/drush
  
      state:  link
  

  
  - name: Check out Drual Core to apache docroot
  
    git:
  
      repo: http://git.drupal.org/project/drupal.git
  
      version:  "{{ drupal_core_version }}"
  
      dest: "{{ drupal_core_path }}"
  

  
  - name: Install Drual  # 在指定的目录安装drual,生成settings.php文件
  
    command:  >
  
      drush si -y --site-name="{{ drupal_site_name }}" --account-name=admin --account-pass=admin --db-url=mysql://root@localhost/{{ domain }}
  
      chdir={{ drupal_core_path }}
  
      creates={{ drupal_core_path }}/sites/default/settings.php
  
    notify: restart apache
  

  
  - name: Set permisions properly on settings.php # 修改文件权限
  
    file:
  
      path: "{{ drupal_core_path }}/sites/default/settings.php"
  
      mode: 0744
  

  
  - name: Set permissions on files directory # 修改目录权限
  
    file:
  
      path: "{{ drupal_core_path }}/sites/default/files"
  
      mode: 0777
  
      state:  directory
  
      recurse:  yes

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-543285-1-1.html 上篇帖子: ansible应用进阶playbook--LNMP+WordPress 下篇帖子: ansible小技巧
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表