ansible

Copy file from one remote server to another remote server using nested delegate_to

自古美人都是妖i 提交于 2020-01-05 05:39:10
问题 As a user I want to copy file from node1 to node2. Is it possible with copy module + delegate_to Below is what I was trying to do. Playbook is running from node3. Playbook Sample --- - name: Gather Facts for all hosts hosts: all gather_facts: true any_errors_fatal: true become: true - name: Test hosts: all gather_facts: false any_errors_fatal: true become: true roles: - role: test Role Sample --- - block: - include_tasks: test.yml any_errors_fatal: true run_once: true Task Sample --- - name:

Loading global environment variables in an Ansible task

纵饮孤独 提交于 2020-01-05 04:35:31
问题 I have several global environment variables set in /etc/environment on my target machine that I need to present when running some Ansible tasks. E.g. MY_VAR=Some global variable The value of these global variables are not known to Ansible so I can't use the environment functionality. Example task: - shell: echo MY_VAR is $MY_VAR register: my_var - debug: msg={{ my_var.stdout }} The output I get is MY_VAR is where I would like it to be MY_VAR is Some global variable . I understand that this is

How to run ansible plays for some tasks on host when playbook is run via Vagrant provisioner?

谁都会走 提交于 2020-01-05 03:36:39
问题 I am using a Ubuntu 16.04 host with Vagrant installed on it. I would like to log the start time and end time of a set of tasks. These tasks are defined as roles. I created a role host_test role to ensure that I am able to touch a file on my host using local_action . But I believe as this playbook is being provisioned via Vagrant, by the time host_test role is played by ansible, Its control is inside the vagrant box rather than outside of it (my intention is to log in the host). So the file is

Ansible syntax best practice, YAML dictionary (key: value) or equal sign (key=value)?

北慕城南 提交于 2020-01-04 14:14:28
问题 I'm used to see Ansible examples as: - file: path=/tmp/file state=touch but someone at work told me that I should be consistent using only YAML syntax like this: - file: path: /tmp/file state: touch or, - file: {path: /tmp/file, state:touch} Which one satisfies Ansible best practices? 回答1: Taken from https://www.ansible.com/blog/ansible-best-practices-essentials At its core, the Ansible playbook runner is a YAML parser with added logic such as commandline key=value pairs shorthand. While

How do I read / understand ansible logs on target host (written by syslog)

落花浮王杯 提交于 2020-01-04 09:37:11
问题 When you execute ansible on some host, it will write to syslog on that host, something like this: Dec 1 15:00:22 run-tools python: ansible-<stdin> Invoked with partial=False links=None copy_links=None perms=None owner=False rsync_path=None dest_port=22 _local_rsync_path=rsync group=False existing_only=False archive=True _substitute_controller=False verify_host=False dirs=False private_key=None dest= compress=True rsync_timeout=0 rsync_opts=None set_remote_user=True recursive=None src=/etc

Ansible setup mysql root password

試著忘記壹切 提交于 2020-01-04 05:45:47
问题 anyone of you have an idea to build a yml for mysql updating of root password and granting privileges? I have created my playbook and on the fresh install its working as expected and no issue at all. But when I do vagrant provision again it now fails to set the root password and I'm getting an error. Below are my codes mysql.yml --- - name: Install the MySQL packages apt: name={{ item }} state=installed update_cache=yes with_items: - mysql-server - mysql-client - python-mysqldb -

Is there a way to validate the number of hosts for a group in Ansible Inventory file?

时光怂恿深爱的人放手 提交于 2020-01-04 05:31:17
问题 My requirement is shown below, I have an Ansible inventory file which is divided into some groups based on the components shown below: [all] node1 node2 node3 node4 [webapp] node3 node4 [ui] node1 Is there a way to validate the number of hosts for a group in inventory file if condition fails then playbook should not run ? My condition is: ui group should always have only one host. Ex: [ui] node1 -- condition check pass proceed with playbook execution [ui] node1 node2 -- condition fails should

学习linux的第七十三天

你说的曾经没有我的故事 提交于 2020-01-04 03:13:41
ansible管理任务计划 使用cron模块来管理任务计划: [root@KXLZQ ~]# ansible testhost -m cron -a “name=‘test cron’ job=’/bin/touch /tmp/ansible_cron.txt’ weekday=1” 192.168.70.129 | SUCCESS => { “changed”: true, “envs”: [], “jobs”: [ “test cron” ] } [root@KXLZQ ~]# 注: name指定一个名称,用于作为标识符,会出现在crontab的注释里 job指定需要执行的命令 weekday表示星期;其他没有设置的时间位默认为 * 客户端查看执行命令: [root@XXQ ~]# crontab -l Lines below here are managed by Salt, do not edit #Ansible: test cron 1 /bin/touch /tmp/ansible_cron.txt 删除该cron ,只需要加一个字段 state=absent: [root@KXLZQ ~]# ansible testhost -m cron -a “name=‘test cron’ state=absent” 192.168.70.129 | SUCCESS =>

How to copy files from remote to host ansible?

旧时模样 提交于 2020-01-04 02:00:26
问题 I am trying to copy files from a remote host to my local server where I am running Ansible playbook. Though the task always executes successfully but the file is never copied to local server. Here is the code: - file: path: vm_info.config mode: 0777 - fetch: src: vm_info.config dest: . #flat: yes fail_on_missing: yes I tried copy module as well but none of them is getting me the result. 回答1: From fetch - Fetches a file from remote nodes dest - A directory to save the file into. For example,

Using Ansible to stop service that might not exist

笑着哭i 提交于 2020-01-04 01:19:14
问题 I am using Ansible 2.6.1 . I am trying to ensure that certain service is not running on target hosts. Problem is that the service might not exist at all on some hosts. If this is the case Ansible fails with error because of missing service. Services are run by Systemd . Using service module: - name: Stop service service: name: '{{ target_service }}' state: stopped Fails with error Could not find the requested service SERVICE: host Trying with command module: - name: Stop service command: