playbook命令行书写格式和jenkins首次使用时遇到的问题

发布时间 2023-08-03 15:03:31作者: solomon123

1, playbook命令行书写格式

-i + ip 地址后面有逗号,否则会报错

命令行如下

ansible-playbook deploy.yml  -i 192.168.1.10, --vault-password-file "../secrets" --extra-vars "host=all"

否则会报错如下

[root@jenkins playbook-test-luodiye-server]# ansible-playbook deploy.yml  -i 192.168.1.10 --vault-password-file "../secrets" --extra-vars "host=all"
[WARNING]: Unable to parse /opt/playbook/playbook-test-luodiye-server/192.168.1.10 as an inventory source
[WARNING]: No inventory was parsed, only implicit localhost is available
[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'

PLAY [Linux Base Configuration] ***************************************************************************************************************************
skipping: no hosts matched

PLAY RECAP ************************************************************************************************************************************************

  

jenkins shell中首次使用playbook 会报错,

TASK [Gathering Facts] *********************************************************
fatal: [192.168.1.10]: FAILED! => {"msg": "Using a SSH password instead of a key is not possible because Host Key checking is enabled and sshpass does not support this.  Please add this host's fingerprint to your known_hosts file to manage this host."}

 

原因是ansible 首次登录需要交互输入yes, 而非直接执行,修改配置文件,去掉选项的注释即可

vim /etc/ansible/ansible.cfg

host_key_checking = False