2019-02-21 Ansible 笔记(一)

ansible应用程序的主配置文件:/etc/ansible/ansible.cfg
其中:
1、默认主机文件在:/etc/ansible/hosts

inventory      = /etc/ansible/hosts

要想使用其他的hosts文件,可以在运行的时候 -i hosts (文件位置)
2、ansible主机需要配置ssh免密登录其他主机,但拷贝完ssh文件(ssh-copy-key) 到该主机后,第一次运行会出现检查keys的对话,导致ssh连接失败,可以在配置文件中取消注释这一句:

host_key_checking = False

3、Ansible默认以root执行,但ubuntu主机通常不用root用户,可以在hosts文件里定义用户名和密码

[ubuntu]
xx.xxx.xxx.xx   ansible_ssh_user=axing  ansible_sudo_pass='password'

4、添加删除用户apple

Anthonys-MacBook-Pro-2:ansible anthony$ ansible ubuntu -i hosts -s -m user -a 'name=apple  shell=/bin/bash  home=/home/apple  state=present'
xx.xxx.xxx.xx | SUCCESS => {
   "changed": true,
    "comment": "",
    "create_home": true,
    "group": 1008,
    "home": "/home/apple",
    "name": "apple",
    "shell": "/bin/bash",
    "state": "present",
    "system": false,
    "uid": 1007
}
Anthonys-MacBook-Pro-2:ansible anthony$ ansible ubuntu -i hosts -s -m user -a 'name=apple  shell=/bin/bash  home=/home/apple  state=absent'
46.102.170.68 | SUCCESS => {
    "changed": true,
    "force": false,
    "name": "apple",
    "remove": false,
    "state": "absent"
}

你可能感兴趣的:(2019-02-21 Ansible 笔记(一))