Mark-20170810-Centos 7 方便快捷安装 Ansible 及 copy 文件/启动 NTP 服务简例
2017-08-10 23:19
731 查看
安装
epel-release 真的好良心啊。yum install -y epel-release yum install -y ansible
顺带找一个 ubuntu 的安装版本
sudo sed -i -re 's/\w+\.archive\.ubuntu\.com/archive.ubuntu.com/g' /etc/apt/sources.list sudo apt-get update sudo apt-get install software-properties-common sudo apt-add-repository ppa:ansible/ansible sudo 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
ubuntuapt - Manages apt-packages
centos
yum - Manages packages with the yum package manager
ansible_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-server sudo 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-copyfilehttp://git.oschina.net/zhoufen111111/ansible-copyfile
1-11111/ansible-ntpservice
http://git.oschina.net/zhoufen111111/ansible-ntpservice/tree/master/
执行
ansible-playbook -i inventory/ copyfile.yaml ansible-playbook -i inventory/ ntpservice.yaml
salt 版
saltstack使用cmd.run批量更改ntp统一时间相关文章推荐
- centos下一键安装lamp环境,快捷,方便
- CentOS5.5下安装zabbix客户端并配置成SysV服务启动
- CentOS 6.3下NTP服务安装和配置
- MongoDB-linux-2.4.10-X86_64(centos/linux下安装,启动服务脚本)
- CentOS6.5使用yum命令方便快捷安装Nginx
- centos下安装mysql(安装,启动,停止,服务端口查询,用户密码设定)
- centos ntp服务配置文件解析
- CentOS6.5_x64安装MySQL-5.6.17,在已经启动MySQL服务的情况下,出现密码报错ERROR 2002 (HY000)
- Centos 7网络文件系统nfs服务的安装与配置
- 解决matlab安装后没有快捷方式启动弹出DOS界面并且m文件无关联的方法
- SQL Server 服务无法启动。有关详细信息,请参阅 SQL Server 联机丛书中的主题“如何查看 SQL Server 2005 安装日志文件”和“手动启动 SQL Server”
- SQL Server 服务无法启动.有关详细信息,请参阅SQL Server联机丛书中的主题"如何查看SQL Server 2005 安装日志文件"和"手动启动SQL Server"
- centos安装启动ssh服务
- CentOS6.5使用yum命令方便快捷安装Nginx
- hadoop学习;安装jdk,workstation虚拟机v2v迁移;虚拟机之间和跨物理机之间ping网络通信;virtualbox的centos中关闭防火墙和检查服务启动
- Centos 7 安装lnmp 移动数据库文件目录,重启后无法访问Web服务,笔记
- centos 启动慢+ 用户不在sudoers文件中+安装chkconfig命令
- CentOS 6.3下NTP服务安装和配置
- Tomcat解压版安装后不能快捷启动报未安装某tomcat服务
- CentOS安装MongoDB后无法启动服务的解决办法