您的位置:首页 > 运维架构 > Linux

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

ubuntu

apt - 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-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.yaml
ansible-playbook -i inventory/ ntpservice.yaml


salt 版

saltstack使用cmd.run批量更改ntp统一时间
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  centos ansible yum
相关文章推荐