任務,我試着寫一個小ansible,劇本對服務器的基本設置,而是從角色我的任務拒絕運行:))Ansible劇本不運行從角色
劇本有這樣的目錄結構:
└── install
├── group_vars
│ └── all.yml
├── roles
│ ├── basic_setup
│ │ └── tasks
│ │ └── main.yml
│ └── user_management
│ └── tasks
│ └── main.yml
└── setup.yml
setup.yml樣子:
---
- hosts: '{{ target }}'
become: yes
remote_user: root
roles:
- { role: basic_setup }
- { role: user_management }
而且,例如,我的install/roles/basic_setup/tasks/main.yml
樣子:
---
- name: Install python2.7
raw: test -e /usr/bin/python || (apt -y update && apt install -y python-minimal)
when: ansible_os_family == "Debian"
- name: 'test this playbook'
shell: "echo 'hello world'"
當我嘗試運行的劇本我得到這個輸出:
$ ansible-playbook install/setup.yml --ask-pass --user=root --extra-vars "target=192.168.1.228" -vvv
Using /etc/ansible/ansible.cfg as config file
SSH password:
_____________________
< PLAYBOOK: setup.yml >
---------------------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
1 plays in install/setup.yml
____________
< PLAY RECAP >
------------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
文件install/roles/user_management/tasks/main.ym
升看起來是這樣的:
---
- name: Ensure bogdan user
user:
name: admin
state: present
- name: Ensure ssh key access
authorized_key:
key: "{{ lookup('file', key_path) }}"
user: admin
state: present
- name: Ensure admin user user is sudoer
lineinfile:
dest: /etc/sudoers
line: "admin ALL=(ALL) NOPASSWD:ALL"
regexp: '^admin ALL\='
state: present
validate: "visudo -cf %s"
- name: Create deployer user
user:
name: deployer
state: present
- name: Ensure ssh key access
authorized_key:
key: "{{ lookup('file', key_path) }}"
user: deployer
state: present
有人可以幫助我瞭解我究竟做錯了什麼?
你可以請禁用Cowsay(https://docs.ansible.com/ansible/faq.html#how-do-i-disable-cowsay)。 –
@techraf,遠程服務器上沒有任何事情發生。目前沒有產出。 Ansible不會輸出運行多少任務,有多少個失敗等等。 – kitz
@el_wichtel,輸出沒有cowsay: '$ ansible-playbook install/setup.yml --ask-pass --extra-vars「target = 192.168.1.228「-vvvvv 使用/etc/ansible/ansible.cfg作爲配置文件 SSH密碼: 從/usr/lib/python2.7/dist-packages/加載回調插件默認類型stdout,v2.0 ansible/plugins/callback/__ init __。pyc PLAYBOOK:setup.yml ********************************** ************************** 在install/setup.yml中播放1次 PLAY RECAP *********** ************************************************** ********' – kitz