我将继续表达Ansible的文档,并分析不了解它的后果(链接到上一部分)。
在这一部分中,我们讨论库存。我也答应了变量,但是库存实际上是一个很大的话题,因此我们专门为它写了一篇文章。
我们将分析广告资源的每个元素(除外host_group_vars plugin
),并讨论其原因,如何正确使用它以及错误之处。
目录:
- 什么是主机?(有关运输的一些知识)
- IP vs FQDN访问;
inventory_hostname
与ansible_host
ansible_user
-写还是不写?- 团体
- 变量:广告资源还是剧本?
- 按产地分类库存。
清单是主机,组以及辅助变量的列表。在学习基础知识的过程中,我们将详细分析每一个时刻,并寻找“应该”的方式和对“如何”的谴责。
库存:主机
— hosts
yaml- ( ini- — ):
somegroup:
hosts:
somehost1:
somehost2:
somehost1, somehost2 — .
"" , ? , , — , . . , VM, , , ipmi' ..
: , - . , : , ssh ( , ); ( ); , lxc-. , - .
: - , , . libvirt. , — "vms" - . : , - ssh ...
… - , include_role: configure_vm
, ansible_host
, ssh vm_ip somecommand
,… , .
: , - () .
: Openstack' , API ? ?
: . . , , "".
: management_ip
?
: - ( dlink_configure
) - , . , , , .
, - :
) ( - ).
) (delegate_to
).
, , . -, ( ) . . - localhost project-global ( — ). -, -, , all
( all
). WTF , . -, ( -) .
: ansible_host vs FQDN
, inventory_hostname
, ansible_host
, .
, "", , play — , .
""? "connection plugin" , (, , , ). - . ssh ( -), . , : ansible_host
, ansible_user
, ansible_port
. . . , lxc ( lxc-execute
), ?
ansible_host
, inventory_hostname
. — .
:
---
somegroup:
hosts:
somehost:
ansible_host: 254.12.11.10
somehost
— inventory_hostname
. ansible_host
, inventory_hostname
. , , , .
inventory_hostname
, ansible_host
, . , . " " . . , lxc . ssh ( , ) - .
-, ~/.ssh/ssh_config
( , ). , , ssh - . .. ( ) - , ( ) . , jump-, ssh-. , . ssh_config
( ssh_config
), ssh gethostbyname()
. libc, . , , (/etc/nsswitch.conf
, /etc/hosts
) DNS- ( ). , , , DNS-, , CNAME … , .
, , : SSH, ( ) ansible_host
IP-.
, . .
-, host-local (ssh_config
, /etc/hosts
), . -, . CI, . , , - (?) , . ( ), . .
, , . , /etc/hosts . , .
DNS, . DNS ? / , . , , CI? - , DNS- — . . .
, . ansible_host
inventory_hostname
?
" ". setup
:
- name: Ping neighbor
command: ping -c 1 {{ neighbor_ip }} -w 1
changed_when: false
vars:
neighbor_ip: '{{ (hostvars[item].ansible_all_ipv4_addresses|ipaddr(public_network))[0] }}'
with_items: '{{ groups[target_group] }}'
( public_network
, target_group
).
, , . 99% " ". , ansible_host
IP-, . setup
. . ansible_host
IP- , , "- IP ", (!) , IP- "access address" , .. . .
… : , (- ) DNS? , . , , , IP. , .
: ansible_user
: ? , . , .
- - "" ? ,
ansible_user
. - "" ? ,
ansible_user
. - ,
-u
ansible-playbook
, , . . , CI-u
( ), . - . , 'me'. . — m.gavriilicheynko. .
- ,
ansible-playbook -e ansible_user=ci
( CI, ) , ( , ). - " " ( , ),
-u
, .
( , ), ansible_user
"" (.. , ). — ansible_user (, ..), ansible_user
.
, " ", "". , . — , .
Ansible?
-, " " ( hosts
play groups
). -, , . , , ( hosts , ). , , . .
( — , ):
- play. (
hosts
). , 'prometheus' , Prometheus. - - . , , (" " ), , - , , — () .
- .
, , .
— . , , (, play) — . , , .
. — . jc-r4, xcore-lu1 ams1-se-r2, "netflow_collectors". ? , , , , , / , .
. , , — , , , . .
, — . , " ".
— , .
— play. , play ( — docker). , play ( ), , play.
. — .
:
---
foo:
hosts:
foo1:
foo2:
bar:
hosts:
bar1
foobar:
children:
foo:
bar:
— . play - . ( , , , , , , grafana-servers mons — mgrs ).
" mgrs mons" . DRY (do not repeat yourself, ) , .
.
— - , "" . group_by
add_host
.
, . , ( ). , , . , — . — , . , --limit
. group_by
, , .. --limit
. [always], . , group_by
— , inventory . .
, "" (.. ). , — ? ( "", hashmap, map, object, ..). , . , ( 2.4 play: order
, inventory
).
? , :
-
groups.somegroup[0]
" ". , , . . . - (,
pg_hba.conf
,allowed
nginx.conf
, etc). , changed. , reload', changed . - , , .
, "", .
. , openstack', Openstack, , , . ( , , — , ""). . . ( ) . - -. , . , staging . , - - . --, , . - . , . - - ? , "". ? , . … , . IP, . , . . , .
, , , , , . , , - , .
:
— . , , . play , ( DRY) , "" (variable precedence). , , , .
… : ?
. — . , ( jinja). "". "" ?
- "", - "", - "". ( ""). , ( ). , — .
"" . , , ansible_host
, hostvars .. ( , , ). .
, , ( ) "", ( ) — "". , .
… . , , , ( best practices, — , ). "" , , , , .
" " . . DRY , , — - . .
: , java- , ?
: , (, ), . — staging production, .
: localhost, ( nginx proxy_pass
), ?
: , .
: — ?
: , . , , — .
, . , : " "? , — , .
, . ?
, " ".
— . production.yaml
, staging.yaml
, production/
staging/
, , . () . " " . . , . , " " ( , , , etc).
— . - git , , , - git . , . - (ansible, ceph, openshift, etc) . , . API, "" . , , , , .
. , . ( , , ). "" — () , (, , ceph-ansible' RGW ).
— ( ). , . CI — . — . — , , . DRY, . . .
. , — 3000 10 , , — , CI.
— . , , , , .
.
ansible-playbook -i inventory1.yaml -i inventory2.yaml play.yaml
" ". - ( ), (, inventory2.yaml
users: [...]
, inventory1.yaml
).
? , , , .
: (host_vars/
, group_vars
). , ( ) (). Edge case, .
" " / . , , , , , . " ". .
: