ansible-inventory 命令

Ansible 2.4中秘密添加的inventory文件信息,提供了一个可以将其整齐地输出的命令。
与常规的ansible-*命令一样,可以使用“-i”指定inventory文件,使用“-l”指定限制。
如果想要输出为yaml格式,则需要添加“-y”。

使用enginyoyen/ansible-best-practises进行尝试

– 图表

以树形方式展示群组和主机的关联。同时解决指定的嵌套子节点。

ansible-best-practises> ansible-inventory -i production.ini --graph
@all:
  |--@postgresql:
  |  |--postgresql000.prod.example.com
  |--@ungrouped:
  |--@webservers:
  |  |--webserver000.prod.example.com
  |  |--webserver001.prod.example.com
  |  |--webserver002.prod.example.com
  |  |--webserver003.prod.example.com
  |  |--webserver004.prod.example.com

–主机名称 主机名

指定一个单一的主机并收集group_vars和host_vars来显示变量。

ansible-best-practises> ansible-inventory -i production.ini --host webserver000.prod.example.com
{
    "apt_default_key_urls": [
        "http://nginx.org/keys/nginx_signing.key"
    ],
    "apt_default_packages": [
        "nginx=1.6.2-1~precise"
    ],
    "apt_default_repositories": [
        "deb http://nginx.org/packages/ubuntu/ precise nginx",
        "deb-src http://nginx.org/packages/ubuntu/ precise nginx"
    ],
    "apt_update_source_list": "template",
    "apt_update_source_list_mirror": "http://nl.archive.ubuntu.com/ubuntu/",
    "environment": "prod",
    "nginx_apt_state": "present",
    "nginx_etc": "/etc/nginx",
    "nginx_install_repo": "nginx",
    "nginx_max_clients": 1024,
    "unattended_install": true,
    "webserver000_host_vars": "000_vars"
}

– 名单

将所有信息(包括组和元数据)dump到主机中。

由于较长,已省略。ansible-best-practises> ansible-inventory -i production.ini –list
{
“_meta”: {
“hostvars”: {
“postgresql000.prod.example.com”: {
“apt_default_packages”: [
“python-apt”,
“unattended-upgrades”,
“language-pack-en-base”,
“unzip”
],
“apt_update_source_list”: “template”,
“apt_update_source_list_mirror”: “http://nl.archive.ubuntu.com/ubuntu/”,
“environment”: “prod”,
“postgresql_cluster_reset”: true,
“postgresql_data_directory”: “/mnt/db/postgresql/{{postgresql_version}}/{{postgresql_cluster_name}}”,
“postgresql_databases”: [
{
“name”: “products”
},
{
“name”: “partners”
}
],
“postgresql_listen_addresses”: [
“0.0.0.0”
],
“postgresql_pg_hba_trust_hosts”: [
“0.0.0.0/0”
],
“postgresql_user_privileges”: [
{
“db”: “products”,
“name”: “jane”
},
{
“db”: “partners”,
“name”: “joe”
}
],
“postgresql_users”: [
{
“name”: “jane”,
“pass”: “{{ postgresql_users_jane }}”
},
{
“name”: “joe”,
“pass”: “{{ postgresql_users_joe }}”
}
],
“unattended_install”: true
},
“webserver000.prod.example.com”: {
“apt_default_key_urls”: [
“http://nginx.org/keys/nginx_signing.key”
],
“apt_default_packages”: [
“nginx=1.6.2-1~precise”
],
“apt_default_repositories”: [
“deb http://nginx.org/packages/ubuntu/ precise nginx”,
“deb-src http://nginx.org/packages/ubuntu/ precise nginx”
],
“apt_update_source_list”: “template”,
“apt_update_source_list_mirror”: “http://nl.archive.ubuntu.com/ubuntu/”,
“environment”: “prod”,
“nginx_apt_state”: “present”,
“nginx_etc”: “/etc/nginx”,
“nginx_install_repo”: “nginx”,
“nginx_max_clients”: 1024,
“unattended_install”: true,
“webserver000_host_vars”: “000_vars”
},
“webserver001.prod.example.com”: {
“apt_default_key_urls”: [
“http://nginx.org/keys/nginx_signing.key”
],
“apt_default_packages”: [
“nginx=1.6.2-1~precise”
],
“apt_default_repositories”: [
“deb http://nginx.org/packages/ubuntu/ precise nginx”,
“deb-src http://nginx.org/packages/ubuntu/ precise nginx”
],
“apt_update_source_list”: “template”,
“apt_update_source_list_mirror”: “http://nl.archive.ubuntu.com/ubuntu/”,
“environment”: “prod”,
“nginx_apt_state”: “present”,
“nginx_etc”: “/etc/nginx”,
“nginx_install_repo”: “nginx”,
“nginx_max_clients”: 1024,
“unattended_install”: true
},
“webserver002.prod.example.com”: {
“apt_default_key_urls”: [
“http://nginx.org/keys/nginx_signing.key”
],
“apt_default_packages”: [
“nginx=1.6.2-1~precise”
],
“apt_default_repositories”: [
“deb http://nginx.org/packages/ubuntu/ precise nginx”,
“deb-src http://nginx.org/packages/ubuntu/ precise nginx”
],
“apt_update_source_list”: “template”,
“apt_update_source_list_mirror”: “http://nl.archive.ubuntu.com/ubuntu/”,
“environment”: “prod”,
“nginx_apt_state”: “present”,
“nginx_etc”: “/etc/nginx”,
“nginx_install_repo”: “nginx”,
“nginx_max_clients”: 1024,
“unattended_install”: true
},
“webserver003.prod.example.com”: {
“apt_default_key_urls”: [
“http://nginx.org/keys/nginx_signing.key”
],
“apt_default_packages”: [
“nginx=1.6.2-1~precise”
],
“apt_default_repositories”: [
“deb http://nginx.org/packages/ubuntu/ precise nginx”,
“deb-src http://nginx.org/packages/ubuntu/ precise nginx”
],
“apt_update_source_list”: “template”,
“apt_update_source_list_mirror”: “http://nl.archive.ubuntu.com/ubuntu/”,
“environment”: “prod”,
“nginx_apt_state”: “present”,
“nginx_etc”: “/etc/nginx”,
“nginx_install_repo”: “nginx”,
“nginx_max_clients”: 1024,
“unattended_install”: true
},
“webserver004.prod.example.com”: {
“apt_default_key_urls”: [
“http://nginx.org/keys/nginx_signing.key”
],
“apt_default_packages”: [
“nginx=1.6.2-1~precise”
],
“apt_default_repositories”: [
“deb http://nginx.org/packages/ubuntu/ precise nginx”,
“deb-src http://nginx.org/packages/ubuntu/ precise nginx”
],
“apt_update_source_list”: “template”,
“apt_update_source_list_mirror”: “http://nl.archive.ubuntu.com/ubuntu/”,
“environment”: “prod”,
“nginx_apt_state”: “present”,
“nginx_etc”: “/etc/nginx”,
“nginx_install_repo”: “nginx”,
“nginx_max_clients”: 1024,
“unattended_install”: true
}
}
},
“all”: {
“children”: [
“postgresql”,
“ungrouped”,
“webservers”
],
“vars”: {
“environment”: “prod”
}
},
“postgresql”: {
“hosts”: [
“postgresql000.prod.example.com”
]
},
“ungrouped”: {},
“webservers”: {
“hosts”: [
“webserver000.prod.example.com”,
“webserver001.prod.example.com”,
“webserver002.prod.example.com”,
“webserver003.prod.example.com”,
“webserver004.prod.example.com”
]
}
}

bannerAds