43

ansible 简明教程

 5 years ago
source link: https://jiajunhuang.com/articles/2017_06_22-ansible.md.html?amp%3Butm_medium=referral
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

ini格式的配置文件大家都懂吧。

先编写一个host文件例如:

[local]
127.0.0.1

保存为 localhost.ini

然后执行 ansible -i ./test.host.ini local -k -a 'ls'

就会有输出:

SSH password: 
127.0.0.1 | SUCCESS | rc=0 >>
code
docs
source
test

其中 ansible 的命令大致的格式就是 ansible [group] -a [command] group就是host文件里的组,默认有 allungroup 两个组,最后就是要执行的命令。 详见: http://docs.ansible.com/ansible/intro_patterns.html

-a 就是导入了一个默认模块,用来执行命令的。 -m 则用来导入特定模块,这个就需要 具体用到具体翻文档了。

也可以在家目录下新建一个 ansible.cfg 然后指定默认去找哪个host文件

[defaults]
inventory = ./test.host.ini

然后就可以这样干: ansible local -k -a 'ls' 了。具体很多配置可以参考这里: http://docs.ansible.com/ansible/intro_configuration.html

当然啦, ansible 只是一个临时用的命令,如果想多次使用一些命令,就可以上 ansible-playbook 了。

文档在: http://docs.ansible.com/ansible/playbooks.html

里面有很多模块,在: http://docs.ansible.com/ansible/modules_by_category.html

还有一个概念是role,这个瞄了几眼但是还没看完: http://docs.ansible.com/ansible/playbooks_roles.html


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK