ansible

Get the pid of a running playbook for use within the playbook

笑着哭i 提交于 2019-12-30 17:22:43
问题 When we run a playbook, with verbose output enabled, in the ansible logs we can see something like this: 2016-02-03 12:51:58,235 p=4105 u=root | PLAY RECAP I guess that the p=4105 is the pid of the playbook when it ran. Is there a way to get this pid inside the playbook during its runtime (as a variable for example)? 回答1: This sounds a little like an XY problem, but one option may be to spawn a shell with the shell command and then ask for the parent PID: - name: get pid of playbook shell: |

Ansible Register Multiple Async Tasks to the Same Variable

人盡茶涼 提交于 2019-12-30 12:03:19
问题 Is there a way to register multiple async tasks to the same variable? For example if I have two tasks that each invoke an async shell command: - name: Run async task 1 shell: echo "task 1" async: 30 poll: 0 register: db_wait - name: Run async task 2 shell: echo "task 2" async: 30 poll: 0 register: db_wait - debug: msg="task vars {{db_wait}}" When I print the db_wait variable it only contains the reference of one task. "msg": "task vars {u'started': 1, u'results_file': u'/home/vagrant/.ansible

Ansible Register Multiple Async Tasks to the Same Variable

风格不统一 提交于 2019-12-30 12:03:08
问题 Is there a way to register multiple async tasks to the same variable? For example if I have two tasks that each invoke an async shell command: - name: Run async task 1 shell: echo "task 1" async: 30 poll: 0 register: db_wait - name: Run async task 2 shell: echo "task 2" async: 30 poll: 0 register: db_wait - debug: msg="task vars {{db_wait}}" When I print the db_wait variable it only contains the reference of one task. "msg": "task vars {u'started': 1, u'results_file': u'/home/vagrant/.ansible

ansible get aws ebs volume id which already exist

半城伤御伤魂 提交于 2019-12-30 10:43:16
问题 I'm trying to get the aws volume id which already exist and attached to ec2 instance using ansible. I have a lookup task using the ec2_remote_facts module that get details of the ec2 instance including the volume id details the task: - name: lookup ec2 virtual machines ec2_remote_facts: aws_access_key: "{{aws_access_key}}" aws_secret_key: "{{aws_secret_key}}" region: "{{ec2_region}}" filters: instance-state-name: running "tag:Name": "{{server_name}}" "tag:Environment": "{{environment_type}}"

Ansible date compare EC2

社会主义新天地 提交于 2019-12-30 10:31:39
问题 I am new to Ansible . I created EC2 instances using ansible and able to to retrieve the launch time using EC2 facts . But i am unable to store the launch time in date format . My goal is to get the difference of launch time date with system date (unable to find that also and perform some operations . Any guidance is appreciated . Regards, Naresh Sharma 回答1: Since Ansible 2.2 there is a handy to_datetime(format) filter available. Here is example for your task: --- - hosts: localhost gather

Ansible date compare EC2

六月ゝ 毕业季﹏ 提交于 2019-12-30 10:31:32
问题 I am new to Ansible . I created EC2 instances using ansible and able to to retrieve the launch time using EC2 facts . But i am unable to store the launch time in date format . My goal is to get the difference of launch time date with system date (unable to find that also and perform some operations . Any guidance is appreciated . Regards, Naresh Sharma 回答1: Since Ansible 2.2 there is a handy to_datetime(format) filter available. Here is example for your task: --- - hosts: localhost gather

Get sorted list of folders with Ansible

隐身守侯 提交于 2019-12-30 08:33:24
问题 I have OS X "El capitan" 10.11.6 and I am using Ansible 2.1.1.0 to run some maintenance tasks on a remote Linux server Ubuntu 16.04 Xenial . I am trying to get the following list of folders sorted, so I can remove the old ones when needed: /releases/0.0.0 /releases/0.0.1 /releases/0.0.10 /releases/1.0.0 /releases/1.0.5 /releases/2.0.0 I have been trying with the module find in Ansible, but it returns a not sorted list. Is there an easy way to achieve this with Ansible? 回答1: You can sort items

YAML: When an equals sign (=) can be used for dictionaries?

ぐ巨炮叔叔 提交于 2019-12-30 07:24:09
问题 I read key1=value1 key2=value2 style dictionaries all the time in ansible playbooks that are supposed to be written in YAML. On the other hand I didn't find any documentation for this format and there seem to be cases where it doesn't work for me. What is the exact specification and where can I find it? 回答1: In Ansible key=value is not used for dicts in general. It is an alternative syntax to pass parameters to actions/modules, like: - name: restart apache service: name=apache state=restarted

Is there anyway to run multiple Ansible playbooks as multiple users more efficiently?

梦想与她 提交于 2019-12-30 06:58:34
问题 Currently my playbook structure is like this: ~/test_ansible_roles ❯❯❯ tree . . ├── checkout_sources │ └── tasks │ └── main.yml ├── install_dependencies │ └── tasks │ └── main.yml ├── make_dirs │ └── tasks │ └── main.yml ├── setup_machine.yml One of the roles that I have is to install dependencies on my box, so for this I need sudo . Because of that all of my other tasks I need to include the stanza: become: yes become_user: my_username Is there a better way to do this ? 回答1: You can set the

Is there anyway to run multiple Ansible playbooks as multiple users more efficiently?

我的未来我决定 提交于 2019-12-30 06:58:17
问题 Currently my playbook structure is like this: ~/test_ansible_roles ❯❯❯ tree . . ├── checkout_sources │ └── tasks │ └── main.yml ├── install_dependencies │ └── tasks │ └── main.yml ├── make_dirs │ └── tasks │ └── main.yml ├── setup_machine.yml One of the roles that I have is to install dependencies on my box, so for this I need sudo . Because of that all of my other tasks I need to include the stanza: become: yes become_user: my_username Is there a better way to do this ? 回答1: You can set the