How to pass variables to included tasks in ansible?

Faced the same issue in my project. It turns out that the variable name in the playbook and the task have to be different. — – name: The name hosts: all vars: my_var_play: “I need to send this value to the task” some_other_var: “This is directly accessible in task” tasks: – include:my_tasks.yml vars: my_var: “{{ … Read more

Order of notify handlers

I think you may have “restart docker” listed before “daemon reload” in your handlers file. That part of the ansible documentation is a bit misleading. It means that handlers are executed in the order they are written in the handlers file, not the order they are notified. This is little more clear in the documentation: … Read more

Running ansible-playbook using Python API

Deprecation Notice: This post doesn’t work as of Ansible 2. The API was changed. This is covered in the Ansible documentation under “Python API.” For example, ansible -i hosts dbservers -m setup is implemented via: import ansible.runner runner = ansible.runner.Runner( module_name=”setup”, module_args=””, pattern=’dbservers’, ) dbservers_get_facts = runner.run() There are a bunch of non-documented parameters in … Read more

Ansible and Wget

Don’t use shell-module when there is specialized modules available. In your case: Create directories with file-module: – name: create project directory {{ common.project_dir }} file: state=directory path={{ common.project_dir }} Download files with get_url-module: – name: download sources get_url: url={{ opencv.url }} dest={{ common.project_dir }}/{{ opencv.file }} Note the new module call syntax in the examples … Read more

How to create new system service by ansible-playbook

The below code snippet will create Service in CentOS 7. Code Tasks /tasks/main.yml – name: TeamCity | Create environment file template: src=teamcity.env.j2 dest=/etc/sysconfig/teamcity – name: TeamCity | Create Unit file template: src=teamcity.service.j2 dest=/lib/systemd/system/teamcity.service mode=644 notify: – reload systemctl – name: TeamCity | Start teamcity service: name=teamcity.service state=started enabled=yes Templates /templates/teamcity.service.j2 [Unit] Description=JetBrains TeamCity Requires=network.target After=syslog.target … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)