ansible-playbook系列之常用操作

往期回顾

环境默认使用root,如果非root下查看下列文章

ansible-playbook系列之apt更新软件

init

[client]chrony.conf

cat > /etc/chrony/chrony.conf << EOF
confdir /etc/chrony/conf.d
pool 10.6.0.254        iburst
pool 192.168.1.101        iburst
pool 192.168.1.254        iburst
sourcedir /run/chrony-dhcp
sourcedir /etc/chrony/sources.d
keyfile /etc/chrony/chrony.keys
driftfile /var/lib/chrony/chrony.drift
ntsdumpdir /var/lib/chrony
logdir /var/log/chrony
maxupdateskew 100.0
rtcsync
makestep 1 3
leapsectz right/UTC
EOF

hostname.sh

#!/bin/bash

name_host="work" && hostnamectl set-hostname ${name_host}$(ip a | grep -i inet | grep -Eow '([0-9]{1,3}\.){3}[0-9]{1,3}' | grep -vEw "127.0.0.1|255" | head -n 1 | tr -d '.')
hostname="${name_host}$(ip a | grep -i inet | grep -Eow '([0-9]{1,3}\.){3}[0-9]{1,3}' | grep -vEw "127.0.0.1|255" | head -n 1 | tr -d '.')"
hosts_exits="$(cat /etc/hosts | grep -i ${hostname} | wc -l)"

if [[ ${hosts_exits} -eq 0 ]];then
    echo -e "$(ip a show $(ip route | grep -i default | awk '{ print $5 }') | grep -Eow 'inet ([0-9]{1,3}\.){3}[0-9]{1,3}' | grep -Eow '([0-9]{1,3}\.){3}[0-9]{1,3}')\t$(hostname)" | tee -a /etc/hosts
else
    echo "hostname exits"
fi

init_application.yml

更新源、安装指定软件、

---
- name: init_application
  hosts: execgroup
  remote_user: root
  gather_facts: true

  tasks:
    - name: Update apt cache
      apt:
        update_cache: yes
      tags: update

    - name: Install and upgrade software
      apt:
        name: 
          - build-essential
          - chrony
          - forta
          - pkg-config
        state: latest
        force_apt_get: yes

    - name: Copy chrony.conf
      copy:
        src: /root/ansible_miner/chrony.conf
        dest: /etc/chrony/chrony.conf
        mode: '0644'

    - name: Enable chrony
      shell: systemctl enable chrony

    - name: Start chrony
      shell: systemctl start chrony

    - name: set timezone Asia/Shanghai
      shell: timedatectl set-timezone Asia/Shanghai

    - name: Copy hostname.sh to /tmp
      copy:
        src: /root/ansible_miner/hostname.sh
        dest: /tmp/hostname.sh
        mode: '0755'

    - name: Execute the hostname.sh script
      shell: /bin/bash /tmp/hostname.sh
暂无评论

发送评论 编辑评论


|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇