添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
相关文章推荐
乖乖的椅子  ·  3.2 Ansible ...·  2 天前    · 
伤情的创口贴  ·  org.apache.ibatis.exec ...·  6 月前    · 
坏坏的铁板烧  ·  python ...·  1 年前    · 

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement . We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account
[root@80e0fa0abea3 opt]# ansible --version
ansible 2.8.4
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.7.5 (default, Aug  7 2019, 00:51:29) [GCC 4.8.5 20150623 (Red Hat 4.8.5-39)]
CONFIGURATION
[root@80e0fa0abea3 opt]# ansible-config dump --only-changed
[root@80e0fa0abea3 opt]# 
OS / ENVIRONMENT
CentOS Linux release 7.6.1810 (Core) 
STEPS TO REPRODUCE

If you run ansible-playbook test.yml -i <INVENTORY>, ansible-playbook works as expected because an inventory is specified for Ansible to target.

[root@80e0fa0abea3 opt]# ansible-playbook -i tower_hosts -vv test.yml --limit=CentOS2
ansible-playbook 2.8.4
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/site-packages/ansible
  executable location = /usr/bin/ansible-playbook
  python version = 2.7.5 (default, Aug  7 2019, 00:51:29) [GCC 4.8.5 20150623 (Red Hat 4.8.5-39)]
Using /etc/ansible/ansible.cfg as config file
PLAYBOOK: test.yml ********************************************************************************************************************************************************************************************
1 plays in test.yml
PLAY [test] ***************************************************************************************************************************************************************************************************
META: ran handlers
TASK [ping it] ************************************************************************************************************************************************************************************************
task path: /opt/test.yml:7
ok: [CentOS2] => {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python"}, "changed": false, "ping": "pong"}
META: ran handlers
META: ran handlers
PLAY RECAP ****************************************************************************************************************************************************************************************************
CentOS2                    : ok=1    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   

Now, if I take the -i out of ansible-playbook, Ansible doesn't have anything explicitly defined to target. However, ansible-playbook still exits with 0:

[root@80e0fa0abea3 opt]# ansible-playbook -vv test.yml --limit=CentOS2
ansible-playbook 2.8.4
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/site-packages/ansible
  executable location = /usr/bin/ansible-playbook
  python version = 2.7.5 (default, Aug  7 2019, 00:51:29) [GCC 4.8.5 20150623 (Red Hat 4.8.5-39)]
Using /etc/ansible/ansible.cfg as config file
 [WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'
 [WARNING]: Could not match supplied host pattern, ignoring: CentOS2
PLAYBOOK: test.yml ********************************************************************************************************************************************************************************************
1 plays in test.yml
PLAY [test] ***************************************************************************************************************************************************************************************************
skipping: no hosts matched
PLAY RECAP ****************************************************************************************************************************************************************************************************
[root@80e0fa0abea3 opt]# echo $?
EXPECTED RESULTS

I would expect that ansible-playbook should require an inventory or hosts to target, like -i.

[root@80e0fa0abea3 opt]# ansible-playbook -i tower_hosts -vv test.yml --limit=CentOS2
ansible-playbook 2.8.4
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/site-packages/ansible
  executable location = /usr/bin/ansible-playbook
  python version = 2.7.5 (default, Aug  7 2019, 00:51:29) [GCC 4.8.5 20150623 (Red Hat 4.8.5-39)]
Using /etc/ansible/ansible.cfg as config file
PLAYBOOK: test.yml ********************************************************************************************************************************************************************************************
1 plays in test.yml
PLAY [test] ***************************************************************************************************************************************************************************************************
META: ran handlers
TASK [ping it] ************************************************************************************************************************************************************************************************
task path: /opt/test.yml:7
ok: [CentOS2] => {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python"}, "changed": false, "ping": "pong"}
META: ran handlers
META: ran handlers
PLAY RECAP ****************************************************************************************************************************************************************************************************
CentOS2                    : ok=1    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   
ACTUAL RESULTS

Even when no hosts are explicitly defined, Ansible still exits with 0 (i.e. ansible-playbook was successful).

[root@80e0fa0abea3 opt]# ansible-playbook -vv test.yml --limit=CentOS2
ansible-playbook 2.8.4
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/site-packages/ansible
  executable location = /usr/bin/ansible-playbook
  python version = 2.7.5 (default, Aug  7 2019, 00:51:29) [GCC 4.8.5 20150623 (Red Hat 4.8.5-39)]
Using /etc/ansible/ansible.cfg as config file
 [WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'
 [WARNING]: Could not match supplied host pattern, ignoring: CentOS2
PLAYBOOK: test.yml ********************************************************************************************************************************************************************************************
1 plays in test.yml
PLAY [test] ***************************************************************************************************************************************************************************************************
skipping: no hosts matched
PLAY RECAP ****************************************************************************************************************************************************************************************************

Is this behavior intended?

  • lib/ansible/playbook
  • If these files are inaccurate, please update the component name section of the description or use the !component bot command.

    click here for bot help

    This is expected behavior. You are not required to specify an inventory file, and in such a case only implicit localhost is available.

    It is not an error, when the inventory does not match the specified hosts: in a play, as you can see, it prints a "skipping" message.

    As such, this is a successful run, there were no failures, only skipped plays.

    If you have further questions please stop by IRC or the mailing list:

  • IRC: #ansible on irc.freenode.net
  • mailing list: https://groups.google.com/forum/#!forum/ansible-project
  •