Ansible

作者: 冯延龙 | 来源:发表于2018-09-20 11:36 被阅读0次

centos7 环境下

安装

yum install ansible

配置远程受控机的信息

/etc/ansible/host文件中配置

[server-test]
192.168.11.11 ansible_user=user01

生成ssh-key并推送到配置的用户

ssh-keygena -t ras
ssh-copy-id -i ~/.ssh/id_rsa.pub user01@192.168.11.11

测试连通

ansible server-tset -m  command -a "ls -a /home"

使用角色

可以手动建文件夹操作,也可以用ansible-galaxy init <rolename> 来创建。
可以用ansible-galaxy search <rolename> 来搜索现有的role,然后用ansible-galaxy install <rolename> 来安装使用

wait_for 模块

- name: sleep for 300 seconds and continue with play
  wait_for: timeout=300
  delegate_to: localhost

- name: Wait for port 8000 to become open on the host, don't start checking for 10 seconds
  wait_for:
    port: 8000
    delay: 10

- name: Waits for port 8000 of any IP to close active connections, don't start checking for 10 seconds
  wait_for:
    host: 0.0.0.0
    port: 8000
    delay: 10
    state: drained

- name: Wait for port 8000 of any IP to close active connections, ignoring connections for specified hosts
  wait_for:
    host: 0.0.0.0
    port: 8000
    state: drained
    exclude_hosts: 10.2.1.2,10.2.1.3

- name: Wait until the file /tmp/foo is present before continuing
  wait_for:
    path: /tmp/foo

- name: Wait until the string "completed" is in the file /tmp/foo before continuing
  wait_for:
    path: /tmp/foo
    search_regex: completed

- name: Wait until the lock file is removed
  wait_for:
    path: /var/lock/file.lock
    state: absent

- name: Wait until the process is finished and pid was destroyed
  wait_for:
    path: /proc/3466/status
    state: absent

- name: Output customized message when failed
  wait_for:
    path: /tmp/foo
    state: present
    msg: Timeout to find file /tmp/foo

# Don't assume the inventory_hostname is resolvable and delay 10 seconds at start
- name: Wait 300 seconds for port 22 to become open and contain "OpenSSH"
  wait_for:
    port: 22
    host: '{{ (ansible_ssh_host|default(ansible_host))|default(inventory_hostname) }}'
    search_regex: OpenSSH
    delay: 10
  connection: local

# Same as above but you normally have ansible_connection set in inventory, which overrides 'connection'
- name: Wait 300 seconds for port 22 to become open and contain "OpenSSH"
  wait_for:
    port: 22
    host: '{{ (ansible_ssh_host|default(ansible_host))|default(inventory_hostname) }}'
    search_regex: OpenSSH
    delay: 10
  vars:
    ansible_connection: local

相关文章

  • 【Ansible学习】- Ansible初探

    安装 Ansible基础 Ansible架构图 Ansible核心组件说明 Ansible:Ansible的核心程...

  • 快速上手 Ansible

    Ansible 系列:(一):快速上手 Ansible(二):Ansible 命令(三):Ansible 主机清单...

  • Ansible 命令

    Ansible 系列:(一):快速上手 Ansible(二):Ansible 命令(三):Ansible 主机清单...

  • Ansible 主机清单配置文件

    Ansible 系列:(一):快速上手 Ansible(二):Ansible 命令(三):Ansible 主机清单...

  • Ansible Playbook 剧本语法

    Ansible 系列:(一):快速上手 Ansible(二):Ansible 命令(三):Ansible 主机清单...

  • Ansible(一)、实现SSH免密

    1.ansible安装 2.ansible配置 /etc/ansible/ansible.cfg /etc/ans...

  • Ansible第一篇:基础

    一、配置文件 ansible.cfg /etc/ansible/ansible.cfg 是ansible安装好后...

  • 自动化运维-ansible

    目录 十五、ansible介绍十六、ansible安装十七、ansible远程执行命令十八、ansible拷贝文件...

  • 04-invertory

    Ansible Ansible version : 2.6.2 inventory Ansible可以同时处理基础...

  • Ansible部署

    安装ansibleyum install ansible 确认ansible版本ansible --version...

网友评论

      本文标题:Ansible

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