Loops 创建一个playbook test.yml来安装apache2 sqlite3 git?

Loops 创建一个playbook test.yml来安装apache2 sqlite3 git?,loops,ansible,Loops,Ansible,使用的命令:ansible playbook-i myhosts test.yml 错误在1以下,我不知道出了什么问题。有人帮我解决这个问题 错误:加载YAML脚本test.yml时出现语法错误 注意:错误可能实际出现在此位置之前:第7行第12列 --- - name: install apache2, sqlite3, git pn remote server hosts: host01 sudo: yes tasks: - name: Install list of pack

使用的命令:ansible playbook-i myhosts test.yml

错误在1以下,我不知道出了什么问题。有人帮我解决这个问题

错误:加载YAML脚本test.yml时出现语法错误 注意:错误可能实际出现在此位置之前:第7行第12列

---
- name: install apache2, sqlite3, git pn remote server
  hosts: host01
  sudo: yes
  tasks:
  - name: Install list of packages
     action: apt pkg={{item}} state=installed
     with_items:
          - apache2
          - sqlite3
          - git


INVENTORY FILE NAME: myhosts

$cat myhosts

[group1]
host01 ansible_ssh_user=ubuntu
我们可能错了,但这一个看起来可能是一个问题 缺少引号。当模板表达式使用括号时,请始终引用括号 开始一个值。例如:

  - name: Install list of packages
     action: apt pkg={{item}} state=installed
       ^

Indendation似乎是错误的,它应该是两个空格字符的级别,所以尝试使用类似于此的内容来解决缩进问题

    with_items:
      - {{ foo }}

Should be written as:

    with_items:
      - "{{ foo }}"
这适用于我…

给定的命令

---
- hosts: all
  become: yes
  name: install apache2, sqlite3, git pn remote server
  tasks:
  - name: Install list of packages
    action: apt pkg={{item}} state=installed
    with_items:
      - apache2
      - sqlite3
      - git
低于误差

ansible playbook-i myhosts test.yml-b

播放[安装apache2、sqlite3、git pn远程服务器]*************************

收集事实*************************************************************** 致命:[host01]=>SSH错误:SSH:连接到主机host01端口22:连接被拒绝 连接到172.17.3.177:22时 使用-vvv重新运行命令有时很有用,它会打印SSH调试输出以帮助诊断问题

任务:[安装程序包列表]********************************************** 致命:没有匹配的主机或所有主机都已失败--正在中止

重演******************************************************************** 要重试,请使用:--limit@/home/scrapbook/test.retry


host01:ok=0 changed=0 unreachable=1 failed=0

可能重复的问题请解释您的答案与重复问题(前面标记!)中的答案有何不同。问题仍未解决,也许这是一个有效的错误,我们可以修正它,请考虑修改你的答案的代码格式。
---
- hosts: all
  become: yes
  name: install apache2, sqlite3, git pn remote server
  tasks:
  - name: Install list of packages
    action: apt pkg={{item}} state=installed
    with_items:
      - apache2
      - sqlite3
      - git
---
- name: install apache2, sqlite3, git pn remote server
  hosts: host01
  become: yes
  tasks:
  - name: Install list of packages
    action: apt pkg={{item}} state=installed
    with_items:
      - apache2
      - sqlite3
      - git