【问题标题】:ansible playbook runs but does not run any tasksansible playbook 运行但不运行任何任务
【发布时间】:2018-03-30 19:31:18
【问题描述】:

我是 ansible 的新手,创建了一个可以运行但不执行任何任务的剧本。这是我在一个名为 copy 的角色中的任务,此任务将多个文件从 ansible 服务器复制到远程服务器。


- name: Copy Files
  copy:
  src: "{{ item.src }}"
  dest: "{{ item.dest }}"
  with_items:
    - { src: 'audit.rules' , dest: '/etc/audit' }
    - { src: 'issue' , dest: '/etc' }
    - { src: 'issue.net' , dest: '/etc' }
    - { src: 'sshd_config' , dest: '/etc/ssh/' }
    - { src: 'hosts' , dest: '/etc' }
    - { src: 'rsyslog.conf' , dest: '/etc/' }
    - { src: 'sysctl.conf' , dest: '/etc/' }
    - { src: 'ntp.conf' , dest: '/etc/' }

这是我的主要剧本

- hosts: all
  user: root
  roles:
    - copy

这是我运行时的输出,但它不会将任何内容复制到目标主机

[root@hq-lxdev1-ansiblem ansible]# ansible-playbook -i hosts playbook.yml
SSH password:

PLAY [all] **********************************************************************************************************************************************************************************************************************************

TASK [Gathering Facts] **********************************************************************************************************************************************************************************************************************
ok: [10.x.x.x]
        to retry, use: --limit @/etc/ansible/playbook.retry

PLAY RECAP **********************************************************************************************************************************************************************************************************************************
10.x.x.x              : ok=1    changed=0    unreachable=0    failed=0

不知道发生了什么。任何解决此问题的帮助将不胜感激。

【问题讨论】:

    标签: ansible


    【解决方案1】:

    我认为您需要将 srcdest 缩进一个,但如果这是解决方法,那么 Ansible 可能应该警告或可能出错。

    【讨论】:

    • 谢谢亚当,我都识别了,但仍然没有效果。不确定,但我对任务运行了 sytax check 并在 [root@hq-lxdev1-ansiblem tasks]# ansible-playbook copy.yml --syntax-check ERROR 下得到了这个输出! 'dest' 不是 Play 的有效属性错误似乎出现在'/etc/ansible/roles/copyfiles/tasks/copy.yml':第 2 行第 7 列,但可能在文件中的其他位置,具体取决于确切的语法问题。违规行似乎是:--- - name: Copy Files ^ here
    • 似乎除了剧本之外我不能使用 --syntax-check 标志,顺便说一句,我将 copy.yml 的名称更改为 main.yml 并将语法替换为 src=filename dest=解决问题的目录路径。感谢您的帮助
    【解决方案2】:

    我认为srcdest 参数需要比copy 多一级。请试试这个文件并检查它是否有效:

    ---
    - hosts: rhel-blue
      gather_facts: false
    
      tasks:
      - name: Copy Files
        copy:
          src: "{{ item.src }}"
          dest: "{{ item.dest }}"
        with_items:
          - { src: '/etc/hosts' , dest: '/tmp' }
          - { src: '/etc/issue' , dest: '/tmp' }
    

    输出:

    [root@ansible ILIAS]# ansible-playbook copy_files.yml 
    
    PLAY [rhel-blue] ****************************************************************************************************************************************************************************************************
    
    TASK [Copy Files] ***************************************************************************************************************************************************************************************************
    changed: [rhel-blue] => (item={u'dest': u'/tmp', u'src': u'/etc/hosts'})
    changed: [rhel-blue] => (item={u'dest': u'/tmp', u'src': u'/etc/issue'})
    
    PLAY RECAP **********************************************************************************************************************************************************************************************************
    rhel-blue                  : ok=1    changed=1    unreachable=0    failed=0   
    
    [root@ansible ILIAS]# 
    

    【讨论】:

      猜你喜欢
      • 2023-02-25
      • 1970-01-01
      • 1970-01-01
      • 2014-07-19
      • 1970-01-01
      • 1970-01-01
      • 2021-10-15
      • 2017-05-08
      • 1970-01-01
      相关资源
      最近更新 更多