美文网首页
Ansible安装

Ansible安装

作者: 袁先生的笔记 | 来源:发表于2017-08-21 20:55 被阅读0次

    环境

    系统:CentOS 6.8

    Ansible安装

    # yum install epel-release
    # yum install ansible
    

    Ansible配置

    • 配置主文件

      # vim /etc/ansible/ansible.cfg
      inventory = /etc/ansible/inventory
      roles_path = /data/ansible/roles
      remote_user = root
      
    • 创建文件夹

      # mkdir -p /etc/ansible/inventory
      # mkdir -p /data/ansible/playbooks
      # mkdir -p /data/ansible/roles
      # rm -rf /etc/ansible/host
      # rm -rf /etc/ansible/roles
      
    • 配置inventory

      # vim /etc/ansible/inventory/centos
      [group]
      host1
      host2
      
    • 免秘钥登陆

      # ssh-copy-id root@host1
      # ssh-copy-id root@host2
      

    Ansible Ad-Hoc

    • 对group组,使用shell模块,执行hostname命令
      # ansible group -m shell -a 'hostname'
      

    Ansible Playbook

    • 配置Playbook
    # vim /data/ansible/playbooks/centos-os-init.yml
    ---
    - hosts: group
      tasks:
        - name: upgrade all packages
          yum:
            name: '*'
            state: latest
        - name: reboot
          shell: init 6
    
    • 执行Playbook
    # ansible-playbook /data/ansible/playbooks/centos-os-init.yml
    

    相关文章

      网友评论

          本文标题:Ansible安装

          本文链接:https://www.haomeiwen.com/subject/sgvgrxtx.html