【发布时间】:2016-01-19 02:25:58
【问题描述】:
我正在尝试为 django 应用程序的开发和测试环境配置编写 ansible 剧本。但是,在 ansible 任务中使用 when 条件似乎存在问题。
在下面的代码中,任务 2 会在任务 1 更改时执行。它不检查第二个条件。
- name: Task 1
become: yes
command: docker-compose run --rm web python manage.py migrate chdir="{{ server_code_path }}"
when: perform_migration
register: django_migration_result
changed_when: "'No migrations to apply.' not in django_migration_result.stdout"
tags:
- start_service
- django_manage
- name: Task 2 # Django Create Super user on 1st migration
become: yes
command: docker-compose run --rm web python manage.py loaddata create_super_user_data.yaml chdir="{{ server_code_path }}"
when: django_migration_result|changed and ("'Applying auth.0001_initial... OK' in django_migration_result.stdout")
ignore_errors: yes
tags:
- start_service
- django_manage
只要 Task1 更改而不评估第二个条件,任务 2 就会运行
"'Applying auth.0001_initial... OK' in django_migration_result.stdout"
当我尝试不使用 django_migration_result|changed 时,它按预期工作。
- name: Task 2 # Django Create Super user on 1st migration
become: yes
command: docker-compose run --rm web python manage.py loaddata create_super_user_data.yaml chdir="{{ server_code_path }}"
when: "'Applying auth.0001_initial... OK' in django_migration_result.stdout"
以上内容按预期工作。我尝试用布尔变量替换它,即使仍然没有运气。
Ansible 版本:2.0.0.1
任何想法,请帮忙。
【问题讨论】:
标签: yaml jinja2 ansible ansible-playbook