ansibe

https://www.cnblogs.com/zejin2008/p/8321934.html

http://www.ansible.com.cn/docs/playbooks_roles.html

yum install -y epel-release
yum install -y ansible
ssh-keygen  -t rsa -b 4096 -f /root/.ssh/id_rsa

# 输入两个回车确认

---
- hosts: all
  gather_facts: no
  remote_user: root
  vars:
    ansible_ssh_pass: password  # 记得改密码
  tasks:
  - name: Set authorized key taken from file
    authorized_key:
      user: root
      state: present
      key: "{{ lookup('file', '/root/.ssh/id_rsa.pub') }}"
ansible-playbook -i hosts send-pubkey.yml
---
- name: 同步所有节点的 /etc/hosts 文件 并且设置主机名
  hosts: all
  gather_facts: no
  tasks:
    - name: 同步 hosts 文件
      copy: src=/etc/hosts dest=/etc/hosts
    - name: 设置各自的主机名
      shell:
        cmd: hostnamectl set-hostname "{{ inventory_hostname }}"
      register: sethostname
    - name: 验证是否成功设置了主机名
      debug: var=sethostname.rc
...
ansible-playbook -i hosts  send-hosts.yml
#!/bin/bash

set -e

DEVICE=/dev/vdb


if ! [[ -b $DEVICE ]]; then
    echo "Error: device $DEVICE does not exist."
    exit 1
fi

pvcreate $DEVICE

vgcreate data-vg $DEVICE

lvcreate -l +100%FREE -n data-lv data-vg

mkfs.xfs /dev/data-vg/data-lv

mkdir /data

UUID=$(blkid -o value -s UUID /dev/mapper/data--vg-data--lv)

echo "UUID=${UUID} /data xfs defaults 0 0" >> /etc/fstab

mount -a

---
- hosts: work
  become: true
  tasks:
    - name: Execute Bash script
      shell: /etc/ansible/mkfs.sh
      register: script_output
    - name: Print output to console
      debug:
        var: script_output.stdout_lines
ansible work -m copy -a "src=/testdir/copytest dest=/testdir/"
发布日期:
分类:未分类

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注