사용 가능한 플레이 북에서 하나의 작업 만 실행하는 방법은 무엇입니까?
사용 가능한 플레이 북에서 하나의 작업 만 실행할 수있는 방법이 있습니까?
예를 들어에서 roles/hadoop_primary/tasks/hadoop_master.yml
. 나는이 "start hadoop job tracker services"
작업을. 하나의 작업을 실행할 수 있습니까?
hadoop_master.yml 파일 :
---
# Playbook for Hadoop master servers
- name: Install the namenode and jobtracker packages
apt: name={{item}} force=yes state=latest
with_items:
- hadoop-0.20-mapreduce-jobtracker
- hadoop-hdfs-namenode
- hadoop-doc
- hue-plugins
- name: start hadoop jobtracker services
service: name=hadoop-0.20-mapreduce-jobtracker state=started
tags:
debug
http://docs.ansible.com/playbooks_tags.html에tags:
설명 된대로 사용해야합니다.
큰 플레이 북이있는 경우 전체 플레이 북을 실행하지 않고 구성의 특정 부분을 실행하는 것이 유용 할 수 있습니다.
이러한 이유로 놀이와 작업 모두 "tags :"속성을 지원합니다.
예:
tasks:
- yum: name={{ item }} state=installed
with_items:
- httpd
- memcached
tags:
- packages
- template: src=templates/src.j2 dest=/etc/foo.conf
tags:
- configuration
매우 긴 플레이 북의 "구성"및 "패키지"부분 만 실행하려면 다음과 같이하십시오.
ansible-playbook example.yml --tags "configuration,packages"
반면 특정 작업없이 플레이 북을 실행하려면 다음과 같이하십시오.
ansible-playbook example.yml --skip-tags "notification"
역할에 태그를 적용 할 수도 있습니다.
roles:
- { role: webserver, port: 5000, tags: [ 'web', 'foo' ] }
또한 기본 include 문에 태그를 지정할 수도 있습니다.
- include: foo.yml tags=web,foo
이 두 가지 모두 include 문 내의 모든 단일 작업에 태그를 지정하는 기능이 있습니다.
매우 우아하지는 않지만 방법이 있습니다.
ansible-playbook roles/hadoop_primary/tasks/hadoop_master.yml --step --start-at-task='start hadoop jobtracker services'
- 프롬프트가 나타납니다.
Perform task: start hadoop jobtracker services (y/n/c)
- 대답
y
- 다음 프롬프트가 나타납니다.
Ctrl-C
내 플레이 북에서 실행할 작업 하위 집합을 선택할 수 있도록 작업 모음으로 역할을 사용할 수있는 기능을 원합니다. 불행하게도, 플레이 북은 그것들을 모두로드 할 수 --tags
있으며 cmdline 의 옵션 을 사용하여 실행할 작업을 선택해야합니다. 이 문제는 있다는 것입니다 모든 사용자가 설정을 기억하지 않는 한 작업이 실행됩니다 --tags
나 --skip-tags
.
그러나 when:
var가 설정된 경우에만 실행 되는 절을 사용하여 일부 작업을 설정했습니다.
예 :
# role/stuff/tasks/main.yml
- name: do stuff
when: stuff|default(false)
이제이 작업은 기본적으로 실행되지 않지만 설정 한 경우에만 stuff=true
$ ansible-playbook -e '{"stuff":true}'
또는 플레이 북에서 :
roles:
- {"role":"stuff", "stuff":true}
FWIW with Ansible 2.2 one can use include_role:
playbook test.yml
:
- name: test
hosts:
- 127.0.0.1
connection: local
tasks:
- include_role:
name: test
tasks_from: other
then in roles/test/tasks/other.yml
:
- name: say something else
shell: echo "I'm the other guy"
And invoke the playbook with: ansible-playbook test.yml
to get:
TASK [test : say something else] *************
changed: [127.0.0.1]
are you familiar with handlers? I think it's what you are looking for. Move the restart from hadoop_master.yml
to roles/hadoop_primary/handlers/main.yml
:
- name: start hadoop jobtracker services
service: name=hadoop-0.20-mapreduce-jobtracker state=started
and now call use notify
in hadoop_master.yml
:
- name: Install the namenode and jobtracker packages
apt: name={{item}} force=yes state=latest
with_items:
- hadoop-0.20-mapreduce-jobtracker
- hadoop-hdfs-namenode
- hadoop-doc
- hue-plugins
notify: start hadoop jobtracker services
This can be easily done using the tags
The example of tags is defined below:
---
hosts: localhost
tasks:
- name: Creating s3Bucket
s3_bucket:
name: ansiblebucket1234567890
tags:
- createbucket
- name: Simple PUT operation
aws_s3:
bucket: ansiblebucket1234567890
object: /my/desired/key.txt
src: /etc/ansible/myfile.txt
mode: put
tags:
- putfile
- name: Create an empty bucket
aws_s3:
bucket: ansiblebucket12345678901234
mode: create
permission: private
tags:
- emptybucket
to execute the tags we use the command
ansible-playbook creates3bucket.yml --tags "createbucket,putfile"
참고URL : https://stackoverflow.com/questions/23945201/how-to-run-only-one-task-in-ansible-playbook
'IT' 카테고리의 다른 글
왜 int i = 1024 * 1024 * 1024 * 1024가 오류없이 컴파일됩니까? (0) | 2020.06.11 |
---|---|
Java 클래스에서 선언 된 정적 필드 만 검색 (0) | 2020.06.11 |
멤버를 수동으로 폐기하는 방법 (0) | 2020.06.11 |
PyCrypto AES 256을 사용한 암호화 및 복호화 (0) | 2020.06.11 |
HTML 텍스트 영역에 줄 바꿈을 추가하는 방법은 무엇입니까? (0) | 2020.06.11 |