Mark-20170810-Centos 7 方便快捷安装 Ansible 及 copy 文件/启动 NTP 服务简例
来源:互联网 发布:淘宝贷款不还会不会6 编辑:程序博客网 时间:2024/06/05 22:11
安装
epel-release 真的好良心啊。
yum install -y epel-releaseyum install -y ansible
顺带找一个 ubuntu 的安装版本
sudo sed -i -re 's/\w+\.archive\.ubuntu\.com/archive.ubuntu.com/g' /etc/apt/sources.listsudo apt-get updatesudo apt-get install software-properties-commonsudo apt-add-repository ppa:ansible/ansiblesudo apt-get update# 假装以上是需要做的,目前未测试,后补吧。sudo apt-get install ansible
ubuntu14.04安装Ansible
copy 文件
一气呵成,不含杂质,Mark 几个知识点。
ansible.cfg
Ansible 按照如下位置和顺序来查找ansible.cfg 文件:
1. ANSIBLE_CONFIG 环境变量所指定的文件。
2. ./ansible.cfg(当前目录下的ansible.cfg)。
3. ~/.ansible.cfg(主目录下的.ansible.cfg)。
4. /etc/ansible/ansible.cfg。
使用ansible.cfg 文件来简化配置
所以第二个选择相当不错。
第一次登陆报错
Using a SSH password instead of a key is not possible because Host Key checking is enabled and sshpass does not support this. Please add this host's fingerprint to your known_hosts file to manage this host.
解决方法:在ansible.cfg文件中更改下面的参数:
[defaults]host_key_checking = false
ansible运维自动化工具
apt & yum
ubuntu
apt - Manages apt-packagescentos
yum - Manages packages with the yum package manageransible_distribution
Ansible - Conditionals
ssh
ssh - openssh-server
fatal: [172.16.232.132]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: ssh: connect to host 172.16.232.132 port 22: Connection refused\r\n", "unreachable": true}
sudo apt-get install openssh-serversudo service ssh start
root can’t login
fatal: [172.16.232.132]: UNREACHABLE! => {"changed": false, "msg": "Authentication failure.", "unreachable": true}
允许root用户登录ssh(Ubuntu)
daemon-reload
fatal: [172.16.232.132]: FAILED! => {"changed": true, "cmd": "systemctl daemon-reload", "delta": "0:00:00.002450", "end": "2017-08-11 11:29:27.429572", "failed": true, "rc": 127, "start": "2017-08-11 11:29:27.427122", "stderr": "/bin/sh: 1: systemctl: not found", "stderr_lines": ["/bin/sh: 1: systemctl: not found"], "stdout": "", "stdout_lines": []}
- 原:
- name: enable ntp deamon shell: systemctl daemon-reload
- 改:
- name: enable ntp deamon systemd: daemon_reload=yes
systemd - Manage services.
依旧报错。
fatal: [172.16.232.132]: FAILED! => {"changed": false, "failed": true, "msg": "Failed to find required executable systemctl in paths: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"}
ubuntu 没有装 systemctl,不管了。
ansible_os_family 不生效
我果然还是太天真,Ubuntu 对应的是 Debian,CentOS 对应的是 RedHat。
[root@centos ansible-ntpservice]# ansible all -i inventory/ -m setup|more|grep ansible_os_family "ansible_os_family": "Debian", "ansible_os_family": "RedHat",
debug
- name: check ntp status shell: ntpq -p register: result- name: print the ntp status debug: var=result.stdout_lines
Git
- 1-11111/ansible-copyfile
http://git.oschina.net/zhoufen111111/ansible-copyfile
- 1-11111/ansible-ntpservice
http://git.oschina.net/zhoufen111111/ansible-ntpservice/tree/master/
执行
ansible-playbook -i inventory/ copyfile.yamlansible-playbook -i inventory/ ntpservice.yaml
salt 版
saltstack使用cmd.run批量更改ntp统一时间
- Mark-20170810-Centos 7 方便快捷安装 Ansible 及 copy 文件/启动 NTP 服务简例
- Centos 7安装及设置redis自定义服务开机启动
- centos 7 ansible安装篇
- centos 7 使用Ansible 发布tomcat 服务
- ntp 服务编译安装 及 更改端口
- CentOS 7设置NTP、SSH服务
- CentOS启用NTP服务
- CentOS NTP服务搭建
- CentOS 6.3下NTP服务安装和配置
- centos安装ntp服务器
- Centos安装配置NTP
- centOS安装配置ntp
- centos安装启动ssh服务
- centos安装启动ssh服务
- centos安装启动vsftpd服务
- ntp服务安装配置
- Centos 7 phpMyAdmin 服务安装及配置
- Centos 7 nginx服务安装及配置
- 关于STM32的I2S通信飞利浦协议和MSB协议
- 总结我的笔记
- 20170810
- [Python] 新式类中 __new__的理解
- Array2DRandomReverse
- Mark-20170810-Centos 7 方便快捷安装 Ansible 及 copy 文件/启动 NTP 服务简例
- IplImage和Mat访问图像中每个像素
- shell脚本的学习4-函数和重定向
- python学习笔记之006.py
- static学习
- Java默认缓冲大小实验
- DPDK Samples 02l2fwd
- 《笨办法学python》加分习题8——我的答案
- 【如何搭建一个属于自己的独立博客~~~基于windows系统,使用wordpress建站】【弱菜一枚~~大神请路过】