ansible - 从入门到放弃
CLI
ansible ansible-config ansible-console-2 ansible-doc-2 ansible-galaxy-2 ansible-playbook ansible-pull ansible-vault
ansible-2 ansible-connection ansible-console-2.7 ansible-doc-2.7 ansible-galaxy-2.7 ansible-playbook-2 ansible-pull-2 ansible-vault-2
ansible-2.7 ansible-console ansible-doc ansible-galaxy ansible-inventory ansible-playbook-2.7 ansible-pull-2.7 ansible-vault-2.7
cli 根据 ansible-* 切割,动态 import ansible.cli.*,parse -> run
如果是 ansible 命令,那么内部调用 AdHocCLI.run(点对点),直接 Play().load,然后扔给 tqm.run,例:
ansible localhost -m ping
ansible localhost -m setup
ansible all -i $host, -m command -a whoami
all 指 inventory 中的全部主机
如果直接指定 host 需要','隔开,只有一个也要
-m 是模块名,默认是 command
-a 是模块参数
默认是 key 登录,-k 使用密码登录
Inventory & Variables
Playbook
Playbooks are expressed in YAML format
Each playbook is composed of one or more ‘plays’ in a list.
The goal of a play is to map a group of hosts to some well defined roles, represented by things ansible calls tasks. At a basic level, a task is nothing more than a call to an ansible module
Playbook的构造函数只接收一个loader参数,有一个load静态方法用以设置_entries属性,该属性存储plays。
loader返回中间结果ds(dict-list),遍历ds,如果有import_playbook则执行PlaybookInclude.load并把结果extend进来,否则直接append Play.load
Play
class Play(Base, Taggable, Become)
A play is a language feature that represents a list of roles and/or task/handler blocks to execute on a given set of hosts.
Play也有个load方法,根据不同的类型,还有_load_tasks, _load_handlers, _load_roles,最终全部设置到_attributes字典中。
play最终会交由tqm执行(根据不同的strategy有不同的运行方式)。
网友评论