ansible停在注册变量的任务上

时间:2018-12-18 11:50:03

标签: ansible ansible-inventory

我在安装了brew的macos mojave上运行ansible 2.7.0。 我试图在RedHat 7.6(在Linux Academy上)上运行多个任务,其中之一注册了一个变量,该变量确定以下任务。 这是剧本:

- hosts: l1
  become: yes
  handlers:
    - name: restart apache
     #shorthand format:
      service: name="httpd" state="restarted"
      listen: "restart web"
  tasks:
- name: check if DocumentRoot line exists in httpd.conf
  shell: grep "^DocumentRoot:.*$"
  register: if_line_present
- name: create dir /opt/www
  file:
     path: /opt/www
     state: touch
     owner: apache
     group: apache

- name: change config
  replace:
     path: /etc/httpd/conf/httpd.conf
     regexp: '^DocumentRoot.*$'
     replace: 'DocumentRoot "/opt/www"'
     backup: yes
  when: if_line_present.changed
  notify: "restart web"
- name: add DocumentRoot line if it doesn't exist
  lineinfile:
     path: /etc/httpd/conf/httpd.conf
     line: 'DocumentRoot "/opt/www"'
  when: if_line_present.changed == false

我正在使用的广告资源(inv.ini)

[all:vars]
ansible_ssh_user=ansible
ansible_ssh_private_key_file=/Users/vinci/.ssh/id_ftpcerc
l1 ansible_host=lethargos1c.mylabserver.com

ansible-playbook handler_apache.yml -i inv.ini -vvv

TASK [check if DocumentRoot line exists in httpd.conf] ******************************************************************************************************************
task path: /Users/vinci/NextCloud/redhatansible/handler_apache.yml:9
<lethargos1c.mylabserver.com> ESTABLISH SSH CONNECTION FOR USER: ansible
<lethargos1c.mylabserver.com> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o 'IdentityFile="/Users/vinci/.ssh/id_ftpcerc"' -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=ansible -o ConnectTimeout=20 -o ControlPath=/Users/vinci/.ansible/cp/9c281ee913 lethargos1c.mylabserver.com '/bin/sh -c '"'"'echo ~ansible && sleep 0'"'"''
<lethargos1c.mylabserver.com> (0, b'/home/ansible\n', b'')
<lethargos1c.mylabserver.com> ESTABLISH SSH CONNECTION FOR USER: ansible
<lethargos1c.mylabserver.com> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o 'IdentityFile="/Users/vinci/.ssh/id_ftpcerc"' -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=ansible -o ConnectTimeout=20 -o ControlPath=/Users/vinci/.ansible/cp/9c281ee913 lethargos1c.mylabserver.com '/bin/sh -c '"'"'( umask 77 && mkdir -p "` echo /home/ansible/.ansible/tmp/ansible-tmp-1545133310.734169-232778838577862 `" && echo ansible-tmp-1545133310.734169-232778838577862="` echo /home/ansible/.ansible/tmp/ansible-tmp-1545133310.734169-232778838577862 `" ) && sleep 0'"'"''
<lethargos1c.mylabserver.com> (0, b'ansible-tmp-1545133310.734169-232778838577862=/home/ansible/.ansible/tmp/ansible-tmp-1545133310.734169-232778838577862\n', b'')
Using module file /usr/local/Cellar/ansible/2.7.0/libexec/lib/python3.7/site-packages/ansible/modules/commands/command.py
<lethargos1c.mylabserver.com> PUT /Users/vinci/.ansible/tmp/ansible-local-244371dw3ys3/tmpj8tbcvbf TO /home/ansible/.ansible/tmp/ansible-tmp-1545133310.734169-232778838577862/AnsiballZ_command.py
<lethargos1c.mylabserver.com> SSH: EXEC sftp -b - -C -o ControlMaster=auto -o ControlPersist=60s -o 'IdentityFile="/Users/vinci/.ssh/id_ftpcerc"' -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=ansible -o ConnectTimeout=20 -o ControlPath=/Users/vinci/.ansible/cp/9c281ee913 '[lethargos1c.mylabserver.com]'
<lethargos1c.mylabserver.com> (0, b'sftp> put /Users/vinci/.ansible/tmp/ansible-local-244371dw3ys3/tmpj8tbcvbf /home/ansible/.ansible/tmp/ansible-tmp-1545133310.734169-232778838577862/AnsiballZ_command.py\n', b'')
<lethargos1c.mylabserver.com> ESTABLISH SSH CONNECTION FOR USER: ansible
<lethargos1c.mylabserver.com> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o 'IdentityFile="/Users/vinci/.ssh/id_ftpcerc"' -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=ansible -o ConnectTimeout=20 -o ControlPath=/Users/vinci/.ansible/cp/9c281ee913 lethargos1c.mylabserver.com '/bin/sh -c '"'"'chmod u+x /home/ansible/.ansible/tmp/ansible-tmp-1545133310.734169-232778838577862/ /home/ansible/.ansible/tmp/ansible-tmp-1545133310.734169-232778838577862/AnsiballZ_command.py && sleep 0'"'"''
<lethargos1c.mylabserver.com> (0, b'', b'')
<lethargos1c.mylabserver.com> ESTABLISH SSH CONNECTION FOR USER: ansible
<lethargos1c.mylabserver.com> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o 'IdentityFile="/Users/vinci/.ssh/id_ftpcerc"' -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=ansible -o ConnectTimeout=20 -o ControlPath=/Users/vinci/.ansible/cp/9c281ee913 -tt lethargos1c.mylabserver.com '/bin/sh -c '"'"'sudo -H -S -n -u root /bin/sh -c '"'"'"'"'"'"'"'"'echo BECOME-SUCCESS-cvyyahfxeomgpopnvnokkhibncdhcahj; /usr/bin/python /home/ansible/.ansible/tmp/ansible-tmp-1545133310.734169-232778838577862/AnsiballZ_command.py'"'"'"'"'"'"'"'"' && sleep 0'"'"''
Escalation succeeded

之后,它会无限期地停止。有什么事吗?

1 个答案:

答案 0 :(得分:1)

您正在执行的命令

grep "^DocumentRoot:.*$"

未指定,应重新提取WHICH文件。如果未指定文件,则grep从STDIN读取,从而阻止。

指定要grep的文件,您的任务将继续

grep "^DocumentRoot:.*$" /etc/httpd/conf/httpd.conf