2014-10-02 10 views
2

CentOS 6 상자 세트에서 printers.conf를 관리하려고 시도하는 다음과 같은 Unable playbook 파일이 있습니다. 컵 서비스의 정지를 제어하는 ​​조건부 when에서 "locst.stat.md5 북동 remst.stat.md5 : 조건 평가하면서 hostxxx] => 오류 치명적"어떻게 안전하게 printers.conf를 관리 할 수 ​​있습니까?

--- 
# file: roles/common/tasks/config-cups.yml 
# Configure printing 

- name: ensure cups is installed 
    yum: pkg=cups state=installed 

# We want to compare the local and remote printers.conf files so that 
# we can predetermine if the copy needs to happen. According to a 
# comment in the default printers.conf file, we can't write 
# printers.conf while cups is running. But to be idempotent, we want 
# to avoid stopping the cups service if we don't need to. 

- stat: path=printers.conf 
    register: locst 

- stat: path=/etc/cups/printers.conf 
    register: remst 

# can't write printers.conf while running, so says the default file 
- name: ensure cups is stopped 
    service: name=cups state=stopped 
    when: locst.stat.md5 ne remst.stat.md5 

- name: Configure printers 
    tags: configuration 
    copy: > 
    src=printers.conf 
    dest=/etc/cups/printers.conf 
    mode=600 owner=root group=lp 
    notify: 
    - restart cups 

- name: Enable the cups service 
    service: name=cups enabled=yes 

- name: Ensure cups is running 
    service: name=cups state=started 

불행히도 I 오류를 수신한다.

조건부 값을 평가하는 방법이 있습니까? -vvv을 추가하면 여기에 도움이되지 않습니다.

조건부 디버깅 방법이 있습니까?

EDIT1 :

은 분명히 통계 모듈이 항상 원격 -이 역할의 로컬 printers.conf에 대해 일치하지/일반/파일/printers.conf

TASK: [common | stat path=printers.conf] ************************************** 
<hostxxx> ESTABLISH CONNECTION FOR USER[...] 
<hostxxx> REMOTE_MODULE stat path=printers.conf 
[...] 
ok: [hostxxx] => {"changed": false, "stat": {"exists": false}} 

이 될 것이다 조건부를 평가하는 동안 내 "오류"의 출처.

그래서 나는 파일을 깨끗하게 관리하는 방법을 모른다. 나는 작업에 md5 값을 코딩하는 것을 손에 넣고 싶지 않습니다.

stackoverflow question은 거의 동일한 것을 찾습니다.

EDIT2 : 지금 local_action를 사용하여 로컬 파일에 대해 실행 통계 모듈을 얻을 수있어 더 긴 경로 해결 방법 위해 lack of role-path searching in local actions 만 평가하는 동안

, 나는 여전히 같은 오류가 조건부. 올바른 .stat.md5 값을 갖고 있음에도 불구하고.

- local_action: stat path=roles/common/files/printers.conf 
    register: locst 

그러나 나는 md5 값이 예기치 않게 다릅니다. 런타임 중에 컵이 "StateTime"이라는 타임 스탬프라는 것을 비롯하여 printers.conf 파일을 다시 쓰는 것으로 보입니다. config 파일을 작성하여 컵을 관리하는 간단한 방법입니다.

AFAICT는 컵을 깔끔하게 관리 할 수있는 유일한 방법으로, 매번 서비스가 중단 될 때마다 비교하기 전에 기존 printers.conf를 필터링하거나 훨씬 덜 합리적인 방식으로 웹 스캐너를 작성하여 작동하도록합니다. 인터페이스 컵은 프린터 구성에 사용하기를 원합니다.

- name: Configure printers 
    tags: configuration 
    copy: src=printers.conf dest=/etc/cups/printers.conf mode=600 owner=root group=lp validate="service cups stop %s" 

- name: Ensure cups is running 
    service: name=cups state=started 

을 % s는 서비스에 대한 불필요 (: ansible 가정

+0

"stat path = printers.conf"가 로컬 파일과 일치하지 않는 경우 이전에 -vvv 출력에 오류의 원인을 찾았습니다. –

답변

0

당신이 컵을 막을 수있는 유효성 검사 기능을 "확장"수 만 파일과 다른 경우 유효성 검사 명령을 실행하기 때문에 교체하려고 시도합니다 하지만 내 데비안 시스템에는 아무런 영향을 미치지 않습니다.). http://docs.ansible.com/copy_module.html

1

AlexKing의 답변을 시도했지만 제대로 작동하지 못했습니다.이 이미에서 일어나는 것입니다 - 그래서, 다음은 내가 (테스트 작업) 방법 Ansible 작품에 대한 이해에서

- name: Install Printer Driver | Create Kyocera directory as required 
    file: dest=/usr/share/cups/model/Kyocera mode=0755 state=directory owner=root 

- name: Install Printer Driver | Copy PPD file 
    copy: src=Kyocera_TASKalfa_4551ci.PPD dest=/usr/share/cups/model/Kyocera/Kyocera_TASKalfa_4551ci.PPD owner=root group=lp mode=0444 

- name: Install Printer Driver | Ensure cups is stopped before updating the printers.conf file 
    service: name=cups state=stopped 

- name: Install Printer Driver | Configure Printer 
    tags: configuration 
    copy: src=printers.conf dest=/etc/cups/printers.conf mode=600 owner=root group=lp backup=yes 

- name: Install Printer Driver | Ensure cups is running 
    service: name=cups state=started 

,이 파일이 다른 경우 확인할 필요가 없습니다에 결국 무엇인가 복사 모듈.

HTH,

러셀.

0

은 당신의 접근 방식에 몇 가지 잠재적 인 문제를있을 수 있습니다 :

  • - stat: path=printers.conf

    하지 {{ playbook_dir }}/roles/common/
  • MD5 처리에서 로컬 파일은 기본적으로 사용할 수 없습니다, 원격 위치를 나타냅니다. 명시 적으로 작성하는거야 get_md5=yes
  • 사용자가 질문에 따라 /etc/cups/printers.conf

제안 된 솔루션을 찍으하기 위해 작전을 실행하는 sudo는 permitions을해야 할 수도 있습니다 :

--- 
- name: "cups - installation" 
    apt: name=cups state=installed update_cache=yes cache_valid_time=3600 
    become: yes 

- name: "cups - md5 on local printers.conf" 
    local_action: stat path={{ playbook_dir }}/roles/homie/files/printers.conf get_md5=yes 
    register: locst 

- name: "cups - md5 on remote printers.conf" 
    stat: path=/etc/cups/printers.conf get_md5=yes 
    register: remst 
    become: yes 

- name: "cups - stop service" 
    service: name=cups state=stopped 
    when: not remst.stat.exists or (locst.stat.md5 != remst.stat.md5) 
    become: yes 

- name: "cups - configure drivers" 
    copy: src=Canon_MG2900_series.ppd dest=/etc/cups/ppd/Canon_MG2900_series.ppd mode=640 owner=root group=lp backup=yes 
    become: yes 

- name: "cups - configure printers" 
    copy: src=printers.conf dest=/etc/cups/printers.conf mode=600 owner=root group=lp backup=yes 
    notify: restart cups 
    when: not remst.stat.exists or (locst.stat.md5 != remst.stat.md5) 
    become: yes 

및 핸들러 :

--- 
- name: restart cups 
    service: name=cups state=restarted 
    become: yes 

유용함 사용 2.1.0.0